blob: c4f81c3d72e85974adc569cd03d8140d019431a7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
__nwd_cmd=
__nwd_previous_focused=
__nwd_when_started=
__nwd_preexec() {
# Called before executing the command
local no_i3
no_i3=0
[[ -z $DISPLAY || -z $(i3 --get-socketpath) ]] && no_i3=1
[[ $no_i3 -eq 1 || -z $1 ]] && return
__nwd_cmd=$1
__nwd_previous_focused=$(python3 /usr/share/nwd/focused_window.py)
__nwd_when_started=$(date +%s)
}
__nwd_precmd() {
# Called before showing the next prompt
local no_i3
no_i3=0
[[ -z $DISPLAY || -z $(i3 --get-socketpath) ]] && no_i3=1
[[ $no_i3 -eq 1 || -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_previous_focused=
__nwd_cmd=
__nwd_when_started=
}
[[ -z $(echo $preexec_functions|grep __nwd_preexec) ]] && preexec_functions+=(__nwd_preexec)
[[ -z $(echo $precmd_functions|grep __nwd_precmd) ]] && precmd_functions+=(__nwd_precmd)
|