diff options
author | Giuseppe | 2017-06-12 14:47:21 +0200 |
---|---|---|
committer | Giuseppe | 2017-06-12 14:47:21 +0200 |
commit | c3bac3a155294631c9d524c5dc212c34fdc4a554 (patch) | |
tree | d7b33608df20b2d77f1edc3d4db49e4c19f45bea | |
parent | 3d3de010aa25bd4c21884996ce600716767d9c73 (diff) | |
download | aur-c3bac3a155294631c9d524c5dc212c34fdc4a554.tar.gz |
Refactor code.
Use names less likely to collision with other
variables set in current environment; use lower
case when possible.
-rw-r--r-- | .SRCINFO | 2 | ||||
-rw-r--r-- | preexec.sh | 33 |
2 files changed, 22 insertions, 13 deletions
@@ -1,6 +1,6 @@ pkgbase = notify-when-done-i3-git pkgdesc = Get notifications when commands in non-focused i3's window finish. - pkgver = r24.ac9414a + pkgver = r31.3d3de01 pkgrel = 1 url = https://github.com/giuscri/notify-when-done-i3 install = nwd-i3-git.install diff --git a/preexec.sh b/preexec.sh index 720c0bcf5717..b09718cc71c8 100644 --- a/preexec.sh +++ b/preexec.sh @@ -1,19 +1,28 @@ -_precmd() { - if [[ -z $NWD_CMD ]]; then return; fi +__nwd_cmd= +__nwd_previous_focused= +__nwd_when_started= - CURRENT_FOCUSED_W=$(python3 /usr/share/nwd/focused_window.py) - if [[ $NWD_FOCUSED_W && $CURRENT_FOCUSED_W -ne $NWD_FOCUSED_W ]]; then - notify-send -a nwd "$NWD_CMD" +__nwd_precmd() { + [[ -z $__nwd_cmd ]] && return + + local current_focused + current_focused=$(python3 /usr/share/nwd/focused_window.py) + if [[ $__nwd_previous_focused && $current_focused -ne $__nwd_previous_focused ]]; then + local elapsed_seconds + elapsed_seconds=$(( $(date +%s) - $__nwd_when_started )) + [[ $elapsed_seconds -ge 1 ]] && notify-send -a nwd "$__nwd_cmd" fi - NWD_FOCUSED_W= - NWD_CMD= + __nwd_previous_focused= + __nwd_cmd= + __nwd_when_started= } -_preexec() { - NWD_CMD=$1 - NWD_FOCUSED_W=$(python3 /usr/share/nwd/focused_window.py) +__nwd_preexec() { + __nwd_cmd=$1 + __nwd_previous_focused=$(python3 /usr/share/nwd/focused_window.py) + __nwd_when_started=$(date +%s) } -if [[ -z $(echo $preexec_functions|grep _preexec) ]]; then preexec_functions+=(_preexec); fi -if [[ -z $(echo $precmd_functions|grep _precmd) ]]; then precmd_functions+=(_precmd); fi +[[ -z $(echo $preexec_functions|grep __nwd_preexec) ]] && preexec_functions+=(__nwd_preexec) +[[ -z $(echo $precmd_functions|grep __nwd_precmd) ]] && precmd_functions+=(__nwd_precmd) |