diff --git a/qb b/qb index 74aaa80..de0b5fa 100755 --- a/qb +++ b/qb @@ -7,6 +7,7 @@ readonly NBARGS="${#}" [ -z "${DEBUG}" ] && DEBUG=1 ## Colors +readonly PURPLE='\033[1;35m' readonly RED='\033[0;31m' readonly RESET='\033[0m' readonly COLOR_DEBUG="${PURPLE}" @@ -34,6 +35,13 @@ OPTIONS : EOF +} +# }}} +define_vars() { # {{{ + + ## List of process pattern to monitor + qutebrowser_proc_pattern="(qutebrowser)" + } # }}} debug_message() { # {{{ @@ -46,6 +54,29 @@ debug_message() { # {{{ return 0 } # }}} +is_proc_running() { # {{{ + + local_proc_pattern="${1}" + + local_count_proc_pattern="$(pgrep -f -- "${local_proc_pattern}" | wc -l)" + + case "${local_count_proc_pattern}" in + 0 ) ## No procs related to this pattern are running + return_proc_running="1" + ;; + * ) ## At least one proc seems running + return_proc_running="0" + ;; +esac + + ## Simple debug message to valid current variables + debug_message "is_proc_running − \ +procs running (with the pattern: ${RED}${local_proc_pattern}${COLOR_DEBUG}) on the current host: ${RED}${local_count_proc_pattern}${COLOR_DEBUG}." + + return "${return_proc_running}" + +} +# }}} launch_qutebrowser() { # {{{ # Version with user's venv @@ -74,7 +105,14 @@ Start qutebrowser from ${RED}Git repository${COLOR_DEBUG}." main() { # {{{ - launch_qutebrowser \ + ## Define all vars according the selected options + define_vars + + ## If nothing related to Qutebrowser is currently running + ### Try to start qutebrowser + ### Then exit with success + is_proc_running "${qutebrowser_proc_pattern}" \ + || launch_qutebrowser \ && exit 0 }