2020-12-02 10:13:02 +01:00
|
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
|
|
# Vars {{{
|
|
|
|
|
readonly PROGNAME=$(basename "${0}")
|
|
|
|
|
readonly NBARGS="${#}"
|
|
|
|
|
## Test if DEBUG is already defined (by parent script,…)
|
|
|
|
|
[ -z "${DEBUG}" ] && DEBUG=1
|
|
|
|
|
|
|
|
|
|
## Colors
|
2020-12-02 10:36:15 +01:00
|
|
|
|
readonly PURPLE='\033[1;35m'
|
2020-12-02 10:13:02 +01:00
|
|
|
|
readonly RED='\033[0;31m'
|
|
|
|
|
readonly RESET='\033[0m'
|
|
|
|
|
readonly COLOR_DEBUG="${PURPLE}"
|
|
|
|
|
# }}}
|
|
|
|
|
usage() { # {{{
|
|
|
|
|
|
|
|
|
|
cat <<- EOF
|
2020-12-04 11:35:41 +01:00
|
|
|
|
usage: $PROGNAME [--debug,--help]
|
2020-12-02 10:13:02 +01:00
|
|
|
|
|
2020-12-04 11:35:41 +01:00
|
|
|
|
Try to open Qutebrowser content (bookmarks, buffers,…).
|
2020-12-02 10:13:02 +01:00
|
|
|
|
|
|
|
|
|
EXAMPLES :
|
2020-12-04 11:35:41 +01:00
|
|
|
|
- Display content if Qutebrowser is already opened
|
2020-12-02 10:13:02 +01:00
|
|
|
|
${PROGNAME}
|
|
|
|
|
|
|
|
|
|
OPTIONS :
|
|
|
|
|
-d,--debug
|
|
|
|
|
Enable debug messages.
|
|
|
|
|
|
2020-12-04 11:35:41 +01:00
|
|
|
|
-h,--help
|
2020-12-02 10:13:02 +01:00
|
|
|
|
Print this help message.
|
|
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
|
2020-12-02 10:36:15 +01:00
|
|
|
|
}
|
|
|
|
|
# }}}
|
|
|
|
|
define_vars() { # {{{
|
|
|
|
|
|
2020-12-04 11:35:41 +01:00
|
|
|
|
## Test if BROWSER is already defined (by parent script,…)
|
|
|
|
|
[ -z "${BROWSER}" ] && BROWSER="qutebrowser"
|
|
|
|
|
|
2020-12-02 10:36:15 +01:00
|
|
|
|
## List of process pattern to monitor
|
|
|
|
|
qutebrowser_proc_pattern="(qutebrowser)"
|
|
|
|
|
|
2020-12-04 16:43:37 +01:00
|
|
|
|
## Rofi colors
|
|
|
|
|
black="#000000"
|
|
|
|
|
blue="#0094cc"
|
|
|
|
|
|
2020-12-02 14:38:03 +01:00
|
|
|
|
## Store selected content to a temp file
|
|
|
|
|
choice_temp_file="$(mktemp -t ${PROGNAME}-XXXXXX.tmp)"
|
|
|
|
|
|
2020-12-02 18:50:08 +01:00
|
|
|
|
## Variables to get Qutebrowser currents buffers
|
|
|
|
|
QUTEBROWSER_SESSION_FILE="/tmp/qutebrowser_buffers_zsbd"
|
|
|
|
|
QUTEBROWSER_SOCKET_FILE="${XDG_RUNTIME_DIR}/qutebrowser/ipc-$(echo -n "$USER" | md5sum | cut -d' ' -f1)"
|
|
|
|
|
QUTEBROWSER_GLOBAL_CONTENT="/tmp/qutebrowser_global_content"
|
2020-12-02 19:08:03 +01:00
|
|
|
|
rm -f -- "${QUTEBROWSER_GLOBAL_CONTENT}" ; touch "${QUTEBROWSER_GLOBAL_CONTENT}"
|
|
|
|
|
|
2020-12-02 20:01:30 +01:00
|
|
|
|
## Variables to get Qutebrowser *marks from current user
|
2020-12-02 19:08:03 +01:00
|
|
|
|
QUTEBROWSER_QUICKMARK_FILE="${HOME}/.config/qutebrowser/quickmarks"
|
|
|
|
|
QUTEBROWSER_BOOKMARK_FILE="${HOME}/.config/qutebrowser/bookmarks/urls"
|
2020-12-02 18:50:08 +01:00
|
|
|
|
|
2020-12-03 20:01:42 +01:00
|
|
|
|
## Qutebrowser search engines from current user configuration
|
|
|
|
|
QUTEBROWSER_SEARCHENGINE_FILE="${HOME}/.config/qutebrowser/config.py"
|
|
|
|
|
QUTEBROWSER_SEARCHENGINE_LIST="/tmp/qutebrowser_searchengine.list"
|
|
|
|
|
rm -f -- "${QUTEBROWSER_SEARCHENGINE_LIST}" ; touch "${QUTEBROWSER_SEARCHENGINE_LIST}"
|
|
|
|
|
|
2020-12-02 20:01:30 +01:00
|
|
|
|
## Default window pattern to search
|
|
|
|
|
QUTEBROWSER_WINDOW_TITLE="qutebrowser"
|
2020-12-02 10:13:02 +01:00
|
|
|
|
}
|
|
|
|
|
# }}}
|
|
|
|
|
debug_message() { # {{{
|
|
|
|
|
|
|
|
|
|
local_debug_message="${1}"
|
|
|
|
|
|
|
|
|
|
## Print message if DEBUG is enable (=0)
|
|
|
|
|
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6b\e[m\n' "DEBUG − ${PROGNAME} : ${local_debug_message}"
|
|
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
# }}}
|
2020-12-02 15:58:35 +01:00
|
|
|
|
error_message() { # {{{
|
|
|
|
|
|
|
|
|
|
local_error_message="${1}"
|
|
|
|
|
local_error_code="${2}"
|
|
|
|
|
|
|
|
|
|
## Print message if DEBUG is enable (=0)
|
|
|
|
|
[ "${DEBUG}" -eq "0" ] && printf '%b\n' "ERROR − ${PROGNAME} : ${RED}${local_error_message}${RESET}"
|
|
|
|
|
|
|
|
|
|
exit "${local_error_code:=66}"
|
|
|
|
|
}
|
|
|
|
|
# }}}
|
2020-12-02 17:11:36 +01:00
|
|
|
|
is_proc_running() { # {{{
|
|
|
|
|
|
|
|
|
|
local_proc_pattern="${1}"
|
|
|
|
|
|
|
|
|
|
local_count_proc_pattern="$(pgrep -f -- "${local_proc_pattern}" | wc -l)"
|
|
|
|
|
|
|
|
|
|
case "${local_count_proc_pattern}" in
|
|
|
|
|
0 ) ## No procs related to this pattern are running
|
|
|
|
|
return_proc_running="1"
|
|
|
|
|
;;
|
|
|
|
|
* ) ## At least one proc seems running
|
|
|
|
|
return_proc_running="0"
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
## Simple debug message to valid current variables
|
|
|
|
|
debug_message "is_proc_running − \
|
|
|
|
|
procs running (with the pattern: ${RED}${local_proc_pattern}${COLOR_DEBUG}) on the current host: ${RED}${local_count_proc_pattern}${COLOR_DEBUG}."
|
|
|
|
|
|
|
|
|
|
return "${return_proc_running}"
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
# }}}
|
|
|
|
|
start_qutebrowser() { # {{{
|
|
|
|
|
|
|
|
|
|
return_start_qutebrowser="1"
|
|
|
|
|
|
|
|
|
|
if is_proc_running "${qutebrowser_proc_pattern}"; then
|
|
|
|
|
debug_message "start_qutebrowser − \
|
|
|
|
|
Qutebrowser is already started."
|
|
|
|
|
else
|
|
|
|
|
debug_message "start_qutebrowser − \
|
|
|
|
|
No existing instance of Qutebrowser. Starting…" >> /tmp/qb.log
|
2020-12-04 11:35:41 +01:00
|
|
|
|
sh -c "${BROWSER}"
|
2020-12-02 17:11:36 +01:00
|
|
|
|
return_start_qutebrowser="0"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
return "${return_start_qutebrowser}"
|
2020-12-02 10:13:02 +01:00
|
|
|
|
|
2020-12-02 16:35:28 +01:00
|
|
|
|
}
|
|
|
|
|
# }}}
|
|
|
|
|
focus_to_qutebrowser() { # {{{
|
|
|
|
|
|
|
|
|
|
## Get desktop and window ID of the first "qutebrowser" window
|
2020-12-02 20:01:30 +01:00
|
|
|
|
qutebrowser_desktop_id=$(command wmctrl -l | grep --max-count=1 -E -- "${QUTEBROWSER_WINDOW_TITLE}" | cut -d" " -f3)
|
|
|
|
|
qutebrowser_window_id=$(command wmctrl -l | grep --max-count=1 -E -- "${QUTEBROWSER_WINDOW_TITLE}" | cut -d" " -f1)
|
2020-12-02 16:35:28 +01:00
|
|
|
|
|
|
|
|
|
debug_message "focus_to_qutebrowser − \
|
|
|
|
|
Qutebrowser window ID : ${RED}${qutebrowser_window_id}${COLOR_DEBUG} on desktop ID : ${RED}${qutebrowser_desktop_id}${COLOR_DEBUG}."
|
|
|
|
|
|
2020-12-03 08:51:58 +01:00
|
|
|
|
### Switch to Qutebrowser desktop
|
|
|
|
|
command wmctrl -s "${qutebrowser_desktop_id}"
|
|
|
|
|
|
2020-12-02 20:02:35 +01:00
|
|
|
|
## If HerstluftWM is available
|
|
|
|
|
if [ "$(command -v herbstclient)" ]; then
|
|
|
|
|
debug_message "focus_to_qutebrowser − \
|
|
|
|
|
Focus with herbstclient."
|
2020-12-03 08:51:58 +01:00
|
|
|
|
### Focus to the window id
|
2020-12-02 20:02:35 +01:00
|
|
|
|
herbstclient jumpto "${qutebrowser_window_id}"
|
|
|
|
|
else
|
|
|
|
|
debug_message "focus_to_qutebrowser − \
|
|
|
|
|
Focus with wmctrl."
|
2020-12-03 08:51:58 +01:00
|
|
|
|
### Switch expected window
|
2020-12-02 20:02:35 +01:00
|
|
|
|
command wmctrl -i -R "${qutebrowser_window_id}"
|
|
|
|
|
fi
|
2020-12-02 16:35:28 +01:00
|
|
|
|
|
2020-12-02 14:38:03 +01:00
|
|
|
|
}
|
|
|
|
|
# }}}
|
2020-12-02 18:50:08 +01:00
|
|
|
|
get_qutebrowser_buffers() { # {{{
|
|
|
|
|
|
|
|
|
|
## Clear previous buffers list
|
|
|
|
|
[ -f "${QUTEBROWSER_SESSION_FILE}" ] && rm -f -- "${QUTEBROWSER_SESSION_FILE}"
|
|
|
|
|
|
|
|
|
|
## Run save_buffers.py in Qutebrowser
|
|
|
|
|
echo '{"args":[":save-window-and-buffers"], "target_arg":"", "protocol_version":1}' |\
|
|
|
|
|
socat - UNIX-CONNECT:"$QUTEBROWSER_SOCKET_FILE"
|
2020-12-02 14:38:03 +01:00
|
|
|
|
|
2020-12-02 18:50:08 +01:00
|
|
|
|
## Wait to get the buffers list
|
|
|
|
|
i="0"
|
|
|
|
|
while [ "${i}" -lt "5" ]; do
|
|
|
|
|
if [ -f "${QUTEBROWSER_SESSION_FILE}" ]; then
|
|
|
|
|
break
|
|
|
|
|
else
|
|
|
|
|
sleep 0.01
|
|
|
|
|
fi
|
|
|
|
|
i=$((i+1))
|
|
|
|
|
done
|
2020-12-02 14:38:03 +01:00
|
|
|
|
|
2020-12-02 18:50:08 +01:00
|
|
|
|
sed "s/^/ff /g" "${QUTEBROWSER_SESSION_FILE}" >> "${QUTEBROWSER_GLOBAL_CONTENT}"
|
|
|
|
|
|
2020-12-02 19:08:03 +01:00
|
|
|
|
}
|
|
|
|
|
# }}}
|
2020-12-02 19:24:49 +01:00
|
|
|
|
get_qutebrowser_content() { # {{{
|
2020-12-02 19:08:03 +01:00
|
|
|
|
|
|
|
|
|
[ -S "${QUTEBROWSER_SOCKET_FILE}" ] && get_qutebrowser_buffers
|
|
|
|
|
|
2020-12-03 20:01:42 +01:00
|
|
|
|
get_qutebrowser_searchengine
|
|
|
|
|
|
2020-12-02 19:08:03 +01:00
|
|
|
|
[ -f "${QUTEBROWSER_QUICKMARK_FILE}" ] && sed "s/^/qq /g" "${QUTEBROWSER_QUICKMARK_FILE}" >> "${QUTEBROWSER_GLOBAL_CONTENT}"
|
|
|
|
|
[ -f "${QUTEBROWSER_BOOKMARK_FILE}" ] && sed "s/^/bb /g" "${QUTEBROWSER_BOOKMARK_FILE}" >> "${QUTEBROWSER_GLOBAL_CONTENT}"
|
|
|
|
|
|
2020-12-02 18:50:08 +01:00
|
|
|
|
}
|
|
|
|
|
# }}}
|
2020-12-03 20:01:42 +01:00
|
|
|
|
get_qutebrowser_searchengine() { # {{{
|
|
|
|
|
|
|
|
|
|
if [ -f "${QUTEBROWSER_SEARCHENGINE_FILE}" ]; then
|
|
|
|
|
### Store search engine in global list (for display)
|
|
|
|
|
sed -n "s/c.url.searchengines\['\(.*\)'\] = '\(.*\)'$/\1 − \2/p" "${QUTEBROWSER_SEARCHENGINE_FILE}" >> "${QUTEBROWSER_GLOBAL_CONTENT}"
|
|
|
|
|
### And in specific list to verify is an engine was used
|
|
|
|
|
sed -n "s/c.url.searchengines\['\(.*\)'\] = '\(.*\)'$/\1 − \2/p" "${QUTEBROWSER_SEARCHENGINE_FILE}" >> "${QUTEBROWSER_SEARCHENGINE_LIST}"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ -s "${QUTEBROWSER_SEARCHENGINE_LIST}" ]; then
|
|
|
|
|
return_get_qutebrowser_searchengine="0"
|
|
|
|
|
debug_message "get_qutebrowser_searchengine − \
|
|
|
|
|
successfully add search engines from ${QUTEBROWSER_SEARCHENGINE_FILE} file to temp list."
|
|
|
|
|
else
|
|
|
|
|
return_get_qutebrowser_searchengine="1"
|
|
|
|
|
debug_message "get_qutebrowser_searchengine − \
|
|
|
|
|
Can't get search engines list.\
|
|
|
|
|
${RED}${QUTEBROWSER_SEARCHENGINE_FILE}${COLOR_DEBUG} file doesn't exist or impossible to parse."
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
return "${return_get_qutebrowser_searchengine}"
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
# }}}
|
|
|
|
|
goto_qutebrowser_content() { # {{{
|
2020-12-02 18:50:08 +01:00
|
|
|
|
|
2020-12-02 19:08:03 +01:00
|
|
|
|
get_qutebrowser_content
|
2020-12-02 18:50:08 +01:00
|
|
|
|
|
2020-12-03 20:01:42 +01:00
|
|
|
|
debug_message "goto_qutebrowser_content − \
|
2020-12-02 19:08:03 +01:00
|
|
|
|
Search in Qutebrowser's content ${QUTEBROWSER_GLOBAL_CONTENT} file."
|
2020-12-02 18:50:08 +01:00
|
|
|
|
|
2020-12-04 16:43:37 +01:00
|
|
|
|
rofi -dmenu -location 6 -lines 15 -width 80 -p 'Qutebrowser' -color-enabled -color-normal "${black},${blue},${black},${blue},${black}" -color-window "${black},${black}" > "${choice_temp_file}" < "${QUTEBROWSER_GLOBAL_CONTENT}"
|
2020-12-02 14:38:03 +01:00
|
|
|
|
|
|
|
|
|
if [ -s "${choice_temp_file}" ]; then
|
2020-12-03 20:01:42 +01:00
|
|
|
|
debug_message "goto_qutebrowser_content − \
|
2020-12-02 14:38:03 +01:00
|
|
|
|
Store results in ${choice_temp_file}."
|
2020-12-03 20:01:42 +01:00
|
|
|
|
return_goto_qutebrowser_content="0"
|
2020-12-02 14:38:03 +01:00
|
|
|
|
|
|
|
|
|
else
|
2020-12-03 20:01:42 +01:00
|
|
|
|
debug_message "goto_qutebrowser_content − \
|
2020-12-02 14:38:03 +01:00
|
|
|
|
Search aborded or can't find matching bookmark."
|
2020-12-03 20:01:42 +01:00
|
|
|
|
return_goto_qutebrowser_content="1"
|
2020-12-02 16:51:15 +01:00
|
|
|
|
fi
|
|
|
|
|
|
2020-12-03 20:01:42 +01:00
|
|
|
|
return "${return_goto_qutebrowser_content}"
|
2020-12-02 16:51:15 +01:00
|
|
|
|
|
2020-12-02 19:24:49 +01:00
|
|
|
|
}
|
|
|
|
|
# }}}
|
|
|
|
|
open_in_qutebrowser() { # {{{
|
|
|
|
|
|
2020-12-03 20:03:59 +01:00
|
|
|
|
url=$(printf "%s" "${url}" | sed 's/ /%20/g')
|
|
|
|
|
|
2020-12-02 19:24:49 +01:00
|
|
|
|
debug_message "open_in_qutebrowser − \
|
|
|
|
|
Try to open ${RED}${url}${COLOR_DEBUG}"
|
|
|
|
|
|
2020-12-04 11:35:41 +01:00
|
|
|
|
sh -c "${BROWSER} ${url}"
|
2020-12-02 19:24:49 +01:00
|
|
|
|
|
2020-12-02 20:30:05 +01:00
|
|
|
|
}
|
|
|
|
|
# }}}
|
|
|
|
|
is_url_in_buffer() { # {{{
|
|
|
|
|
|
|
|
|
|
if grep -q -E -- "${url}" "${QUTEBROWSER_SESSION_FILE}"; then
|
|
|
|
|
debug_message "is_url_in_buffer − \
|
|
|
|
|
A buffer is already opened with this URL."
|
|
|
|
|
return_is_url_in_buffer="0"
|
|
|
|
|
buffer_id=$(grep -E -- "${url}" "${QUTEBROWSER_SESSION_FILE}" | cut -d" " -f1)
|
|
|
|
|
buffer_title=$(grep -E -- "${url}" "${QUTEBROWSER_SESSION_FILE}" | sed "s;${buffer_id} \(.*\) PyQt5.QtCore.QUrl.*;\1;")
|
|
|
|
|
|
|
|
|
|
switch_qutebrowser_buffer
|
|
|
|
|
else
|
|
|
|
|
debug_message "is_url_in_buffer − \
|
|
|
|
|
No existent buffer with this URL."
|
|
|
|
|
return_is_url_in_buffer="1"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
return "${return_is_url_in_buffer}"
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
# }}}
|
|
|
|
|
goto_url() { # {{{
|
|
|
|
|
|
|
|
|
|
debug_message "goto_url − \
|
|
|
|
|
Manage ${RED}${url}${COLOR_DEBUG} URL"
|
|
|
|
|
|
2021-02-05 08:45:30 +01:00
|
|
|
|
## Go to an existent tab with the expected URL
|
2020-12-02 20:30:05 +01:00
|
|
|
|
### Or open the URL in a new buffer
|
|
|
|
|
is_url_in_buffer \
|
|
|
|
|
|| open_in_qutebrowser
|
|
|
|
|
|
2020-12-02 19:24:49 +01:00
|
|
|
|
}
|
|
|
|
|
# }}}
|
|
|
|
|
switch_qutebrowser_buffer() { # {{{
|
|
|
|
|
|
|
|
|
|
debug_message "switch_qutebrowser_buffer − \
|
|
|
|
|
Try to switch to buffer id: ${buffer_id}."
|
|
|
|
|
|
2021-02-05 08:45:30 +01:00
|
|
|
|
echo "{\"args\":[\":tab-select ${buffer_id}\"], \"target_arg\":\"\", \"protocol_version\":1}" |\
|
2020-12-02 19:24:49 +01:00
|
|
|
|
socat - UNIX-CONNECT:"${QUTEBROWSER_SOCKET_FILE}"
|
|
|
|
|
|
2020-12-02 20:01:30 +01:00
|
|
|
|
## Ensure to focus on expected buffer
|
|
|
|
|
QUTEBROWSER_WINDOW_TITLE="${buffer_title}"
|
|
|
|
|
|
2020-12-03 20:01:42 +01:00
|
|
|
|
}
|
|
|
|
|
# }}}
|
|
|
|
|
use_searchengine() { # {{{
|
|
|
|
|
|
|
|
|
|
return_use_searchengine="0"
|
|
|
|
|
|
|
|
|
|
## If the search engine can't be found
|
|
|
|
|
if ! grep --quiet -E "^${search_engine}" -- "${QUTEBROWSER_SEARCHENGINE_LIST}"; then
|
|
|
|
|
### Set search engine to DEFAULT
|
|
|
|
|
search_engine="DEFAULT"
|
|
|
|
|
### Be sure to take the complete request
|
|
|
|
|
search_request=$(cat "${choice_temp_file}")
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
debug_message "use_searchengine − \
|
|
|
|
|
Use ${RED}${search_engine}${COLOR_DEBUG} search engine."
|
|
|
|
|
|
|
|
|
|
search_url=$(grep -E "^${search_engine}" -- ${QUTEBROWSER_SEARCHENGINE_LIST} | cut --delimiter=" " --field=3)
|
|
|
|
|
debug_message "use_searchengine − \
|
|
|
|
|
Use URL ${RED}${search_url}${COLOR_DEBUG}"
|
|
|
|
|
|
|
|
|
|
url=$(printf "%s" "${search_url}" | sed "s/{}/${search_request}/")
|
|
|
|
|
|
|
|
|
|
goto_url
|
|
|
|
|
|
|
|
|
|
return "${return_use_searchengine}"
|
|
|
|
|
|
2020-12-02 14:38:03 +01:00
|
|
|
|
}
|
|
|
|
|
# }}}
|
2020-12-02 17:31:02 +01:00
|
|
|
|
get_url() { # {{{
|
2020-12-02 14:38:03 +01:00
|
|
|
|
|
|
|
|
|
local_content=$(cat "${choice_temp_file}")
|
|
|
|
|
|
2020-12-02 17:31:02 +01:00
|
|
|
|
return_get_url="1"
|
|
|
|
|
|
|
|
|
|
debug_message "get_url − \
|
2020-12-02 14:38:03 +01:00
|
|
|
|
Try to manage ${RED}$(cat "${choice_temp_file}")${COLOR_DEBUG}."
|
|
|
|
|
|
|
|
|
|
case "${local_content}" in
|
2020-12-02 19:08:03 +01:00
|
|
|
|
bb*http* ) ## Classic bookmark
|
2020-12-02 22:44:42 +01:00
|
|
|
|
url=$(printf "%s" "${local_content}" | cut -d" " -f2)
|
2020-12-02 17:31:02 +01:00
|
|
|
|
return_get_url="0"
|
|
|
|
|
debug_message "get_url − \
|
|
|
|
|
URL from classic bookmark ${RED}${url}${COLOR_DEBUG}."
|
2020-12-02 20:30:05 +01:00
|
|
|
|
goto_url
|
2020-12-02 14:38:03 +01:00
|
|
|
|
;;
|
2020-12-02 19:08:03 +01:00
|
|
|
|
qq*http* ) ## Quickmark
|
2020-12-02 22:44:42 +01:00
|
|
|
|
url=$(printf "%s" "${local_content}" | cut -d" " -f3)
|
2020-12-02 17:31:02 +01:00
|
|
|
|
return_get_url="0"
|
|
|
|
|
debug_message "get_url − \
|
|
|
|
|
URL from quickmark ${RED}${url}${COLOR_DEBUG}."
|
2020-12-02 20:30:05 +01:00
|
|
|
|
goto_url
|
2020-12-02 14:38:03 +01:00
|
|
|
|
;;
|
2020-12-02 19:24:49 +01:00
|
|
|
|
ff* ) ## Buffer
|
|
|
|
|
buffer_id=$(printf "%s" "${local_content}" | cut -d" " -f2)
|
2020-12-02 20:01:30 +01:00
|
|
|
|
buffer_title=$(printf "%s" "${local_content}" | sed "s;ff ${buffer_id} \(.*\) PyQt5.QtCore.QUrl.*;\1;")
|
2020-12-02 19:24:49 +01:00
|
|
|
|
return_get_url="0"
|
2020-12-02 18:50:08 +01:00
|
|
|
|
debug_message "get_url − \
|
2020-12-02 20:01:30 +01:00
|
|
|
|
Buffer title from Qutebrowser: ${RED}${buffer_title}${COLOR_DEBUG}."
|
2020-12-02 19:24:49 +01:00
|
|
|
|
switch_qutebrowser_buffer
|
2020-12-02 18:50:08 +01:00
|
|
|
|
;;
|
2020-12-02 14:38:03 +01:00
|
|
|
|
* )
|
2020-12-03 20:01:42 +01:00
|
|
|
|
search_engine=$(printf "%s" "${local_content}" | cut -d" " -f1)
|
|
|
|
|
search_request=$(printf "%s" "${local_content}" | cut --complement --delimiter=" " --field=1)
|
2020-12-02 17:31:02 +01:00
|
|
|
|
debug_message "get_url − \
|
2020-12-03 20:01:42 +01:00
|
|
|
|
Try to search the content."
|
|
|
|
|
use_searchengine
|
2020-12-02 14:38:03 +01:00
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
2020-12-02 17:31:02 +01:00
|
|
|
|
return "${return_get_url}"
|
|
|
|
|
|
2020-12-02 17:11:36 +01:00
|
|
|
|
}
|
|
|
|
|
# }}}
|
|
|
|
|
goto_existing_qutebrowser() { # {{{
|
|
|
|
|
|
|
|
|
|
debug_message "goto_existing_qutebrowser − \
|
|
|
|
|
Try to open content in existing instance."
|
|
|
|
|
|
2020-12-03 20:01:42 +01:00
|
|
|
|
## Try to open Qutebrowser content (buffer, bookmark, quickmark,…)
|
|
|
|
|
goto_qutebrowser_content \
|
2020-12-02 19:24:49 +01:00
|
|
|
|
&& get_url
|
2020-12-02 17:11:36 +01:00
|
|
|
|
|
2020-12-02 20:01:30 +01:00
|
|
|
|
## Be sure to focus to the expected buffer
|
|
|
|
|
focus_to_qutebrowser
|
|
|
|
|
|
2020-12-02 17:11:36 +01:00
|
|
|
|
return 0
|
|
|
|
|
|
2020-12-02 10:13:02 +01:00
|
|
|
|
}
|
|
|
|
|
# }}}
|
|
|
|
|
|
2020-12-02 10:19:27 +01:00
|
|
|
|
main() { # {{{
|
|
|
|
|
|
2020-12-02 15:48:38 +01:00
|
|
|
|
## Define all vars
|
2020-12-02 10:36:15 +01:00
|
|
|
|
define_vars
|
|
|
|
|
|
2020-12-02 16:51:15 +01:00
|
|
|
|
## Start Qutebrowser if needed
|
|
|
|
|
### And exit
|
|
|
|
|
start_qutebrowser \
|
|
|
|
|
&& exit 0
|
2020-12-02 14:38:03 +01:00
|
|
|
|
|
|
|
|
|
## Manage existing instance
|
2020-12-02 16:35:28 +01:00
|
|
|
|
goto_existing_qutebrowser \
|
|
|
|
|
&& exit 0
|
2020-12-02 10:19:27 +01:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
# }}}
|
|
|
|
|
|
2020-12-02 10:13:02 +01:00
|
|
|
|
# Manage arguments # {{{
|
|
|
|
|
|
|
|
|
|
## If there is argument(s)
|
|
|
|
|
if [ ! "${NBARGS}" -eq "0" ]; then
|
|
|
|
|
|
|
|
|
|
manage_arg="0"
|
|
|
|
|
|
|
|
|
|
# Parse all options (start with a "-") one by one
|
|
|
|
|
while printf -- '%s' "${1}" | grep -q -E -- "^-+"; do
|
|
|
|
|
|
|
|
|
|
case "${1}" in
|
2020-12-02 15:48:38 +01:00
|
|
|
|
-d|--debug ) ## Enable debug mode
|
2020-12-02 10:13:02 +01:00
|
|
|
|
## Enable DEBUG
|
|
|
|
|
DEBUG="0"
|
|
|
|
|
;;
|
|
|
|
|
-h|--help ) ## help
|
|
|
|
|
usage
|
|
|
|
|
## Exit after help informations
|
|
|
|
|
exit 0
|
|
|
|
|
;;
|
|
|
|
|
* ) ## unknow option
|
|
|
|
|
printf '%b\n' "${RED}Invalid option: ${1}${RESET}"
|
|
|
|
|
printf '%b\n' "---"
|
|
|
|
|
usage
|
|
|
|
|
exit 1
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
debug_message "Arguments management − \
|
|
|
|
|
${RED}${1}${COLOR_DEBUG} option managed."
|
|
|
|
|
|
|
|
|
|
## Move to the next argument
|
|
|
|
|
shift
|
|
|
|
|
manage_arg=$((manage_arg+1))
|
|
|
|
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
debug_message "Arguments management − \
|
|
|
|
|
${RED}${manage_arg}${COLOR_DEBUG} argument(s) successfully managed."
|
|
|
|
|
else
|
|
|
|
|
debug_message "Arguments management − \
|
|
|
|
|
No arguments/options to manage."
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# }}}
|
|
|
|
|
|
|
|
|
|
main
|
|
|
|
|
|
|
|
|
|
exit 255
|