Rename return vars and re-order functions

This commit is contained in:
Jeremy Gardais 2020-12-02 17:11:36 +01:00
parent 5bb2d6da76
commit 4ab2928f82
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 81 additions and 81 deletions

162
qb
View File

@ -84,6 +84,59 @@ error_message() { # {{{
exit "${local_error_code:=66}" exit "${local_error_code:=66}"
} }
# }}} # }}}
get_qutebrowser_bin() { # {{{
return_get_qutebrowser_bin="1"
## First try venv {{{
if [ "${QB_VENV_MODE}" -eq "0" ] && [ -f "${QB_VENV_PYTHON_PATH}" ]; then
debug_message "get_qutebrowser_bin \
Qutebrowser from ${RED}venv${COLOR_DEBUG} can be used."
QUTEBROWSER_BIN="${QB_VENV_PYTHON_PATH} -m qutebrowser"
return_get_qutebrowser_bin="0"
### Be sure to skip other MODE if not already defined
[ -z "${QB_PACKAGE_MODE}" ] && QB_PACKAGE_MODE="1"
[ -z "${QB_GIT_MODE}" ] && QB_GIT_MODE="1"
else
debug_message "get_qutebrowser_bin \
Qutebrowser from ${RED}venv${COLOR_DEBUG} not selected or can't be used."
### Be sure to test package MODE
QB_PACKAGE_MODE="0"
fi
## }}}
## Then try package {{{
if [ "${QB_PACKAGE_MODE}" -eq "0" ] && dpkg -l | grep -q qutebrowser ; then
debug_message "get_qutebrowser_bin \
Qutebrowser from ${RED}package${COLOR_DEBUG} will be used."
QUTEBROWSER_BIN="$(command qutebrowser)"
return_get_qutebrowser_bin="0"
### Be sure to skip other MODE if not already defined
[ -z "${QB_GIT_MODE}" ] && QB_GIT_MODE="1"
else
debug_message "get_qutebrowser_bin \
Qutebrowser from ${RED}package${COLOR_DEBUG} not selected or can't be used."
### Allow to try last MODE if not already defined
[ -z "${QB_GIT_MODE}" ] && QB_GIT_MODE="0"
fi
## }}}
## Finally, try git repository {{{
if [ "${QB_GIT_MODE}" -eq "0" ] && [ -f "${QB_GIT_REPOSITORY}/qutebrowser.py" ]; then
QUTEBROWSER_BIN="${QB_GIT_REPOSITORY}/qutebrowser.py --backend webengine"
debug_message "get_qutebrowser_bin \
Qutebrowser from ${RED}Git repository${COLOR_DEBUG} will finally be used."
return_get_qutebrowser_bin="0"
else
debug_message "get_qutebrowser_bin \
Qutebrowser from ${RED}git repository${COLOR_DEBUG} not selected or can't be used."
fi
## }}}
return "${return_get_qutebrowser_bin}"
}
# }}}
is_proc_running() { # {{{ is_proc_running() { # {{{
local_proc_pattern="${1}" local_proc_pattern="${1}"
@ -107,56 +160,24 @@ procs running (with the pattern: ${RED}${local_proc_pattern}${COLOR_DEBUG}) on t
} }
# }}} # }}}
get_qutebrowser_bin() { # {{{ start_qutebrowser() { # {{{
local_get_qutebrowser_bin_return="1" return_start_qutebrowser="1"
## First try venv {{{ if is_proc_running "${qutebrowser_proc_pattern}"; then
if [ "${QB_VENV_MODE}" -eq "0" ] && [ -f "${QB_VENV_PYTHON_PATH}" ]; then debug_message "start_qutebrowser \
debug_message "get_qutebrowser_bin \ Qutebrowser is already started."
Qutebrowser from ${RED}venv${COLOR_DEBUG} can be used."
QUTEBROWSER_BIN="${QB_VENV_PYTHON_PATH} -m qutebrowser"
local_get_qutebrowser_bin_return="0"
### Be sure to skip other MODE if not already defined
[ -z "${QB_PACKAGE_MODE}" ] && QB_PACKAGE_MODE="1"
[ -z "${QB_GIT_MODE}" ] && QB_GIT_MODE="1"
else else
debug_message "get_qutebrowser_bin \ debug_message "start_qutebrowser \
Qutebrowser from ${RED}venv${COLOR_DEBUG} not selected or can't be used." No existing instance of Qutebrowser. Starting…" >> /tmp/qb.log
### Be sure to test package MODE sh -c "${QUTEBROWSER_BIN}"
QB_PACKAGE_MODE="0" return_start_qutebrowser="0"
fi fi
## }}}
## Then try package {{{ ## In any case, be sure to focus to Qutebrowser
if [ "${QB_PACKAGE_MODE}" -eq "0" ] && dpkg -l | grep -q qutebrowser ; then focus_to_qutebrowser
debug_message "get_qutebrowser_bin \
Qutebrowser from ${RED}package${COLOR_DEBUG} will be used."
QUTEBROWSER_BIN="$(command qutebrowser)"
local_get_qutebrowser_bin_return="0"
### Be sure to skip other MODE if not already defined
[ -z "${QB_GIT_MODE}" ] && QB_GIT_MODE="1"
else
debug_message "get_qutebrowser_bin \
Qutebrowser from ${RED}package${COLOR_DEBUG} not selected or can't be used."
### Allow to try last MODE if not already defined
[ -z "${QB_GIT_MODE}" ] && QB_GIT_MODE="0"
fi
## }}}
## Finally, try git repository {{{ return "${return_start_qutebrowser}"
if [ "${QB_GIT_MODE}" -eq "0" ] && [ -f "${QB_GIT_REPOSITORY}/qutebrowser.py" ]; then
QUTEBROWSER_BIN="${QB_GIT_REPOSITORY}/qutebrowser.py --backend webengine"
debug_message "get_qutebrowser_bin \
Qutebrowser from ${RED}Git repository${COLOR_DEBUG} will finally be used."
local_get_qutebrowser_bin_return="0"
else
debug_message "get_qutebrowser_bin \
Qutebrowser from ${RED}git repository${COLOR_DEBUG} not selected or can't be used."
fi
## }}}
return "${local_get_qutebrowser_bin_return}"
} }
# }}} # }}}
@ -173,19 +194,6 @@ Qutebrowser window ID: ${RED}${qutebrowser_window_id}${COLOR_DEBUG} on deskto
command wmctrl -s "${qutebrowser_desktop_id}" command wmctrl -s "${qutebrowser_desktop_id}"
command wmctrl -i -R "${qutebrowser_window_id}" command wmctrl -i -R "${qutebrowser_window_id}"
}
# }}}
goto_existing_qutebrowser() { # {{{
debug_message "goto_existing_qutebrowser \
Try to open content in existing instance."
## Try to open Qutebrowser content
search_qb_bookmark \
&& open_in_qutebrowser
return 0
} }
# }}} # }}}
search_qb_bookmark() { # {{{ search_qb_bookmark() { # {{{
@ -198,36 +206,15 @@ Search in Qutebrowser's bookmarks."
if [ -s "${choice_temp_file}" ]; then if [ -s "${choice_temp_file}" ]; then
debug_message "search_qb_bookmark \ debug_message "search_qb_bookmark \
Store results in ${choice_temp_file}." Store results in ${choice_temp_file}."
local_search_qb_bookmark_return="0" return_search_qb_bookmark="0"
else else
debug_message "search_qb_bookmark \ debug_message "search_qb_bookmark \
Search aborded or can't find matching bookmark." Search aborded or can't find matching bookmark."
local_search_qb_bookmark_return="1" return_search_qb_bookmark="1"
fi fi
return "${local_search_qb_bookmark_return}" return "${return_search_qb_bookmark}"
}
# }}}
start_qutebrowser() { # {{{
local_start_qutebrowser_return="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
sh -c "${QUTEBROWSER_BIN}"
local_start_qutebrowser_return="0"
fi
## In any case, be sure to focus to Qutebrowser
focus_to_qutebrowser
return "${local_start_qutebrowser_return}"
} }
# }}} # }}}
@ -257,6 +244,19 @@ Not yet managed."
~/src/qutebrowser-venv/bin/python3 -m qutebrowser "${local_url}" ~/src/qutebrowser-venv/bin/python3 -m qutebrowser "${local_url}"
}
# }}}
goto_existing_qutebrowser() { # {{{
debug_message "goto_existing_qutebrowser \
Try to open content in existing instance."
## Try to open Qutebrowser content
search_qb_bookmark \
&& open_in_qutebrowser
return 0
} }
# }}} # }}}