aboutsummaryrefslogtreecommitdiff
path: root/zshrc.d/bell
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2018-01-26 15:02:07 +0100
committerKarel Kočí <cynerd@email.cz>2018-01-26 15:26:36 +0100
commit47d3b6fc1966df43b37751165d6fa4229904c0fa (patch)
treecccb190aad69ed1afb93654922575a95e7745d03 /zshrc.d/bell
downloadshellrc-5ca54ae410284b679e1de070dcf74e04bcc5c3f8.tar.gz
shellrc-5ca54ae410284b679e1de070dcf74e04bcc5c3f8.tar.bz2
shellrc-5ca54ae410284b679e1de070dcf74e04bcc5c3f8.zip
Initial commitv0.1
Diffstat (limited to 'zshrc.d/bell')
-rw-r--r--zshrc.d/bell37
1 files changed, 37 insertions, 0 deletions
diff --git a/zshrc.d/bell b/zshrc.d/bell
new file mode 100644
index 0000000..5fbb5c4
--- /dev/null
+++ b/zshrc.d/bell
@@ -0,0 +1,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