Get buffers list from Qutebrowser

This commit is contained in:
gardouille 2020-12-02 18:50:08 +01:00
parent 18d39a2834
commit 05ddce993a
Signed by: gardouille
GPG Key ID: E759BAA22501AF32
1 changed files with 51 additions and 10 deletions

61
qb
View File

@ -61,6 +61,11 @@ define_vars() { # {{{
## Store selected content to a temp file
choice_temp_file="$(mktemp -t ${PROGNAME}-XXXXXX.tmp)"
## 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"
}
# }}}
debug_message() { # {{{
@ -196,25 +201,55 @@ Qutebrowser window ID: ${RED}${qutebrowser_window_id}${COLOR_DEBUG} on deskto
}
# }}}
search_qb_bookmark() { # {{{
get_qutebrowser_buffers() { # {{{
debug_message "search_qb_bookmark \
Search in Qutebrowser's bookmarks."
## Clear previous buffers list
[ -f "${QUTEBROWSER_SESSION_FILE}" ] && rm -f -- "${QUTEBROWSER_SESSION_FILE}"
st -g 90x30+0+540 -n QuteBrowser -t QuteBrowser -e sh -c "cat ~/.config/qutebrowser/quickmarks ~/.config/qutebrowser/bookmarks/urls | fzf +m > ${choice_temp_file}"
## Run save_buffers.py in Qutebrowser
echo '{"args":[":save-window-and-buffers"], "target_arg":"", "protocol_version":1}' |\
socat - UNIX-CONNECT:"$QUTEBROWSER_SOCKET_FILE"
## 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
sed "s/^/ff /g" "${QUTEBROWSER_SESSION_FILE}" >> "${QUTEBROWSER_GLOBAL_CONTENT}"
}
# }}}
search_qb_content() { # {{{
debug_message "search_qb_content \
Search in Qutebrowser's content (*marks, buffers,…)."
## Get current buffers from Qutebrowser
get_qutebrowser_buffers
## Add quickmarks and bookmarks to global Qutebrowser content
cat "${HOME}/.config/qutebrowser/quickmarks" >> "${QUTEBROWSER_GLOBAL_CONTENT}"
cat "${HOME}/.config/qutebrowser/bookmarks/urls" >> "${QUTEBROWSER_GLOBAL_CONTENT}"
st -g 90x30+0+540 -n QuteBrowser -t QuteBrowser -e sh -c "cat ${QUTEBROWSER_GLOBAL_CONTENT} | fzf +m > ${choice_temp_file}"
if [ -s "${choice_temp_file}" ]; then
debug_message "search_qb_bookmark \
debug_message "search_qb_content \
Store results in ${choice_temp_file}."
return_search_qb_bookmark="0"
return_search_qb_content="0"
else
debug_message "search_qb_bookmark \
debug_message "search_qb_content \
Search aborded or can't find matching bookmark."
return_search_qb_bookmark="1"
return_search_qb_content="1"
fi
return "${return_search_qb_bookmark}"
return "${return_search_qb_content}"
}
# }}}
@ -240,6 +275,12 @@ URL from classic bookmark ${RED}${url}${COLOR_DEBUG}."
debug_message "get_url \
URL from quickmark ${RED}${url}${COLOR_DEBUG}."
;;
ff* ) ## Buffer
url=""
return_get_url="1"
debug_message "get_url \
Buffer not yet managed."
;;
* )
debug_message "get_url \
Content not yet managed."
@ -265,7 +306,7 @@ goto_existing_qutebrowser() { # {{{
Try to open content in existing instance."
## Try to open Qutebrowser content
search_qb_bookmark \
search_qb_content \
&& get_url \
&& open_in_qutebrowser