diff --git a/qb b/qb index d5f086a..6b57738 100755 --- a/qb +++ b/qb @@ -15,7 +15,7 @@ readonly COLOR_DEBUG="${PURPLE}" usage() { # {{{ cat <<- EOF -usage: $PROGNAME [--debug,--help] +usage: $PROGNAME [--debug,--help] [--git,--package,--venv] Try to launch the most appropriate qutebrowser binary : 1. From venv @@ -30,9 +30,18 @@ OPTIONS : -d,--debug Enable debug messages. + --git + Force to use QuteBrowser from Git repository. + --help Print this help message. + --package + Force to use QuteBrowser from package. + + --venv + Force to use QuteBrowser from Python Virtual ENVironment. + EOF } @@ -42,6 +51,9 @@ define_vars() { # {{{ ## List of process pattern to monitor qutebrowser_proc_pattern="(qutebrowser)" + ## Use Qutebrowser from Python Virtual Environment by default + QB_VENV_MODE="0" + ## Store selected content to a temp file 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 - 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 + local_get_qutebrowser_bin_return="1" - # Version from APT package - if dpkg -l | grep -q qutebrowser ; then - debug_message "launch_qutebrowser − \ -Start qutebrowser from ${RED}package${COLOR_DEBUG}." - command qutebrowser + ## First try venv {{{ + if [ "${QB_VENV_MODE}" -eq "0" ] && [ -f ~/src/qutebrowser-venv/bin/python3 ]; then + debug_message "get_qutebrowser_bin − \ +Qutebrowser from ${RED}venv${COLOR_DEBUG} can be used." + 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 + ## }}} - # Version from Git repository - if [ -f ~/repos/qutebrowser/qutebrowser.py ]; then - debug_message "launch_qutebrowser − \ -Start qutebrowser from ${RED}Git repository${COLOR_DEBUG}." - ~/repos/qutebrowser/qutebrowser.py --backend webengine + ## 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)" + 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 {{{ + 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() { # {{{ - ## Define all vars according the selected options + ## Define all 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 ### Try to start qutebrowser ### Then exit with success is_proc_running "${qutebrowser_proc_pattern}" \ - || launch_qutebrowser \ + || "${QUTEBROWSER_BIN}" \ || exit 0 ## Manage existing instance @@ -195,15 +243,24 @@ if [ ! "${NBARGS}" -eq "0" ]; then while printf -- '%s' "${1}" | grep -q -E -- "^-+"; do case "${1}" in - -d|--debug ) ## Enable debug mode + -d|--debug ) ## Enable debug mode ## Enable DEBUG DEBUG="0" ;; + --git ) ## Use Git repo + QB_GIT_MODE="0" + ;; -h|--help ) ## help usage ## Exit after help informations exit 0 ;; + --package ) ## Use package + QB_PACKAGE_MODE="0" + ;; + --venv ) ## Use Python venv + QB_VENV_MODE="0" + ;; * ) ## unknow option printf '%b\n' "${RED}Invalid option: ${1}${RESET}" printf '%b\n' "---"