Can choose Qutebrowser bin from argument

This commit is contained in:
Jeremy Gardais 2020-12-02 15:48:38 +01:00
parent 4885bd4ec9
commit 8679335f19
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 78 additions and 21 deletions

97
qb
View File

@ -15,7 +15,7 @@ readonly COLOR_DEBUG="${PURPLE}"
usage() { # {{{ usage() { # {{{
cat <<- EOF cat <<- EOF
usage: $PROGNAME [--debug,--help] usage: $PROGNAME [--debug,--help] [--git,--package,--venv]
Try to launch the most appropriate qutebrowser binary: Try to launch the most appropriate qutebrowser binary:
1. From venv 1. From venv
@ -30,9 +30,18 @@ OPTIONS:
-d,--debug -d,--debug
Enable debug messages. Enable debug messages.
--git
Force to use QuteBrowser from Git repository.
--help --help
Print this help message. Print this help message.
--package
Force to use QuteBrowser from package.
--venv
Force to use QuteBrowser from Python Virtual ENVironment.
EOF EOF
} }
@ -42,6 +51,9 @@ define_vars() { # {{{
## List of process pattern to monitor ## List of process pattern to monitor
qutebrowser_proc_pattern="(qutebrowser)" qutebrowser_proc_pattern="(qutebrowser)"
## Use Qutebrowser from Python Virtual Environment by default
QB_VENV_MODE="0"
## Store selected content to a temp file ## Store selected content to a temp file
choice_temp_file="$(mktemp -t ${PROGNAME}-XXXXXX.tmp)" choice_temp_file="$(mktemp -t ${PROGNAME}-XXXXXX.tmp)"
@ -80,28 +92,56 @@ procs running (with the pattern: ${RED}${local_proc_pattern}${COLOR_DEBUG}) on t
} }
# }}} # }}}
launch_qutebrowser() { # {{{ get_qutebrowser_bin() { # {{{
# Version with user's venv local_get_qutebrowser_bin_return="1"
if [ -f ~/src/qutebrowser-venv/bin/python3 ]; then
debug_message "launch_qutebrowser \
Start qutebrowser from ${RED}venv${COLOR_DEBUG}."
~/src/qutebrowser-venv/bin/python3 -m qutebrowser
fi
# Version from APT package ## First try venv {{{
if dpkg -l | grep -q qutebrowser ; then if [ "${QB_VENV_MODE}" -eq "0" ] && [ -f ~/src/qutebrowser-venv/bin/python3 ]; then
debug_message "launch_qutebrowser \ debug_message "get_qutebrowser_bin \
Start qutebrowser from ${RED}package${COLOR_DEBUG}." Qutebrowser from ${RED}venv${COLOR_DEBUG} can be used."
command qutebrowser QUTEBROWSER_BIN="${HOME}/src/qutebrowser-venv/bin/python3 -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
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 fi
## }}}
# Version from Git repository ## Then try package {{{
if [ -f ~/repos/qutebrowser/qutebrowser.py ]; then if [ "${QB_PACKAGE_MODE}" -eq "0" ] && dpkg -l | grep -q qutebrowser ; then
debug_message "launch_qutebrowser \ debug_message "get_qutebrowser_bin \
Start qutebrowser from ${RED}Git repository${COLOR_DEBUG}." Qutebrowser from ${RED}package${COLOR_DEBUG} will be used."
~/repos/qutebrowser/qutebrowser.py --backend webengine 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 fi
## }}}
## Finally, try git repository {{{
if [ "${QB_GIT_MODE}" -eq "0" ] && [ -f ~/repos/qutebrowser/qutebrowser.py ]; then
QUTEBROWSER_BIN="${HOME}/repos/qutebrowser/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}"
} }
# }}} # }}}
@ -168,14 +208,22 @@ Not yet managed."
main() { # {{{ main() { # {{{
## Define all vars according the selected options ## Define all vars
define_vars define_vars
## Try to get a working qutebrowser binary
### Or exit with error
get_qutebrowser_bin \
|| debug_message "main \
Can't find a working qutebrowser binary." \
|| exit 2
## If nothing related to Qutebrowser is currently running ## If nothing related to Qutebrowser is currently running
### Try to start qutebrowser ### Try to start qutebrowser
### Then exit with success ### Then exit with success
is_proc_running "${qutebrowser_proc_pattern}" \ is_proc_running "${qutebrowser_proc_pattern}" \
|| launch_qutebrowser \ || "${QUTEBROWSER_BIN}" \
|| exit 0 || exit 0
## Manage existing instance ## Manage existing instance
@ -199,11 +247,20 @@ if [ ! "${NBARGS}" -eq "0" ]; then
## Enable DEBUG ## Enable DEBUG
DEBUG="0" DEBUG="0"
;; ;;
--git ) ## Use Git repo
QB_GIT_MODE="0"
;;
-h|--help ) ## help -h|--help ) ## help
usage usage
## Exit after help informations ## Exit after help informations
exit 0 exit 0
;; ;;
--package ) ## Use package
QB_PACKAGE_MODE="0"
;;
--venv ) ## Use Python venv
QB_VENV_MODE="0"
;;
* ) ## unknow option * ) ## unknow option
printf '%b\n' "${RED}Invalid option: ${1}${RESET}" printf '%b\n' "${RED}Invalid option: ${1}${RESET}"
printf '%b\n' "---" printf '%b\n' "---"