aboutsummarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiuseppe2017-06-12 14:47:21 +0200
committerGiuseppe2017-06-12 14:47:21 +0200
commitc3bac3a155294631c9d524c5dc212c34fdc4a554 (patch)
treed7b33608df20b2d77f1edc3d4db49e4c19f45bea
parent3d3de010aa25bd4c21884996ce600716767d9c73 (diff)
downloadaur-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--.SRCINFO2
-rw-r--r--preexec.sh33
2 files changed, 22 insertions, 13 deletions
diff --git a/.SRCINFO b/.SRCINFO
index fab7c41a30a0..2cf73c0bba2a 100644
--- a/.SRCINFO
+++ b/.SRCINFO
@@ -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)