Go to buffer if URL is already opened!

This commit is contained in:
Jeremy Gardais 2020-12-02 20:30:05 +01:00
parent 894fe548ff
commit 689e53ad7c
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 34 additions and 2 deletions

36
qb
View File

@ -279,6 +279,38 @@ Try to open ${RED}${url}${COLOR_DEBUG}"
sh -c "${QUTEBROWSER_BIN} ${url}"
}
# }}}
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"
## Go to an existent buffer with the expected URL
### Or open the URL in a new buffer
is_url_in_buffer \
|| open_in_qutebrowser
}
# }}}
switch_qutebrowser_buffer() { # {{{
@ -309,14 +341,14 @@ Try to manage ${RED}$(cat "${choice_temp_file}")${COLOR_DEBUG}."
return_get_url="0"
debug_message "get_url \
URL from classic bookmark ${RED}${url}${COLOR_DEBUG}."
open_in_qutebrowser
goto_url
;;
qq*http* ) ## Quickmark
url=$(printf "%s" "${local_content}" | sed -e "s;qq .*\(http.*\);\1;")
return_get_url="0"
debug_message "get_url \
URL from quickmark ${RED}${url}${COLOR_DEBUG}."
open_in_qutebrowser
goto_url
;;
ff* ) ## Buffer
buffer_id=$(printf "%s" "${local_content}" | cut -d" " -f2)