blob: 5fbb5c45cfdcf96c26e5954018c0443dbf964922 (
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
|
# vim: ft=zsh
# Long running bell
# Inspired by: https://gist.github.com/jpouellet/5278239
zmodload zsh/datetime # load $EPOCHSECONDS builtin
autoload -Uz add-zsh-hook
lrbell_duration=15
lrbell_timestamp=$EPOCHSECONDS
lrbell_window_id=0x0
lrbell_active_window_id() {
xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2
}
lrbell_begin() {
lrbell_timestamp=$EPOCHSECONDS
if [ -n "$DISPLAY" ]; then
lrbell_message="`pwd`: $1"
lrbell_window_id="$(lrbell_active_window_id)"
fi
}
lrbell_end() {
if (( $EPOCHSECONDS - $lrbell_timestamp < $lrbell_duration )); then
return
fi
print -n '\a'
if [ -n "$DISPLAY" ] && [ -n "$lrbell_window_id" ]; then # notify only if running in X
if [ "$(lrbell_active_window_id)" != "$lrbell_window_id" ]; then # And active window isn't current one
notify-send "Command finished" "$lrbell_message"
fi
fi
}
add-zsh-hook preexec lrbell_begin
add-zsh-hook precmd lrbell_end
|