Start qutebrowser only if not already running

This commit is contained in:
Jeremy Gardais 2020-12-02 10:36:15 +01:00
parent 472fa7e563
commit 3e3c377035
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 39 additions and 1 deletions

40
qb
View File

@ -7,6 +7,7 @@ readonly NBARGS="${#}"
[ -z "${DEBUG}" ] && DEBUG=1 [ -z "${DEBUG}" ] && DEBUG=1
## Colors ## Colors
readonly PURPLE='\033[1;35m'
readonly RED='\033[0;31m' readonly RED='\033[0;31m'
readonly RESET='\033[0m' readonly RESET='\033[0m'
readonly COLOR_DEBUG="${PURPLE}" readonly COLOR_DEBUG="${PURPLE}"
@ -34,6 +35,13 @@ OPTIONS:
EOF EOF
}
# }}}
define_vars() { # {{{
## List of process pattern to monitor
qutebrowser_proc_pattern="(qutebrowser)"
} }
# }}} # }}}
debug_message() { # {{{ debug_message() { # {{{
@ -46,6 +54,29 @@ debug_message() { # {{{
return 0 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() { # {{{ launch_qutebrowser() { # {{{
# Version with user's venv # Version with user's venv
@ -74,7 +105,14 @@ Start qutebrowser from ${RED}Git repository${COLOR_DEBUG}."
main() { # {{{ 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 && exit 0
} }