scripts/qb

132 lines
2.7 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/sh
# Vars {{{
readonly PROGNAME=$(basename "${0}")
readonly NBARGS="${#}"
## Test if DEBUG is already defined (by parent script,…)
[ -z "${DEBUG}" ] && DEBUG=1
## Colors
readonly RED='\033[0;31m'
readonly RESET='\033[0m'
readonly COLOR_DEBUG="${PURPLE}"
# }}}
usage() { # {{{
cat <<- EOF
usage: $PROGNAME [--debug,--help]
Try to launch the most appropriate qutebrowser binary:
1. From venv
2. From APT package
3. From Git repository
EXAMPLES:
- Launch qutebrowser
${PROGNAME}
OPTIONS:
-d,--debug
Enable debug messages.
--help
Print this help message.
EOF
}
# }}}
debug_message() { # {{{
local_debug_message="${1}"
## Print message if DEBUG is enable (=0)
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6b\e[m\n' "DEBUG ${PROGNAME}: ${local_debug_message}"
return 0
}
# }}}
launch_qutebrowser() { # {{{
# 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
# Version from APT package
if dpkg -l | grep -q qutebrowser ; then
debug_message "launch_qutebrowser \
Start qutebrowser from ${RED}package${COLOR_DEBUG}."
command qutebrowser
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
fi
}
# }}}
main() { # {{{
launch_qutebrowser \
&& exit 0
}
# }}}
# Manage arguments # {{{
## If there is argument(s)
if [ ! "${NBARGS}" -eq "0" ]; then
manage_arg="0"
# Parse all options (start with a "-") one by one
while printf -- '%s' "${1}" | grep -q -E -- "^-+"; do
case "${1}" in
-d|--debug ) ## Enable debug mode
## Enable DEBUG
DEBUG="0"
;;
-h|--help ) ## help
usage
## Exit after help informations
exit 0
;;
* ) ## unknow option
printf '%b\n' "${RED}Invalid option: ${1}${RESET}"
printf '%b\n' "---"
usage
exit 1
;;
esac
debug_message "Arguments management \
${RED}${1}${COLOR_DEBUG} option managed."
## Move to the next argument
shift
manage_arg=$((manage_arg+1))
done
debug_message "Arguments management \
${RED}${manage_arg}${COLOR_DEBUG} argument(s) successfully managed."
else
debug_message "Arguments management \
No arguments/options to manage."
fi
# }}}
main
exit 255