From 47d3b6fc1966df43b37751165d6fa4229904c0fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Fri, 26 Jan 2018 15:02:07 +0100 Subject: Initial commit --- zshrc.d/bell | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 zshrc.d/bell (limited to 'zshrc.d/bell') 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 -- cgit v1.2.3