aboutsummarylogtreecommitdiffstats
path: root/preexec.sh
blob: 769bda6f810f58b47e8608761d9a3f750e98382c (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
__nwd_cmd=
__nwd_previous_focused=
__nwd_when_started=

__nwd_precmd() {
    local abort
    abort=0
    [[ -z $DISPLAY || $(pgrep i3|wc -l) -eq 0 ]] && abort=1
    [[ $abort -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=
}

__nwd_preexec() {
    local abort
    abort=0
    [[ -z $DISPLAY || $(pgrep i3|wc -l) -eq 0 ]] && abort=1
    [[ $abort -eq 1 && -z $__nwd_cmd ]] && return

    __nwd_cmd=$1
    __nwd_previous_focused=$(python3 /usr/share/nwd/focused_window.py)
    __nwd_when_started=$(date +%s)
}

[[ -z $(echo $preexec_functions|grep __nwd_preexec) ]] && preexec_functions+=(__nwd_preexec)
[[ -z $(echo $precmd_functions|grep __nwd_precmd) ]] && precmd_functions+=(__nwd_precmd)