aboutsummaryrefslogtreecommitdiff
path: root/zshrc
diff options
context:
space:
mode:
authorKarel Kočí <karel.koci@nic.cz>2016-09-12 08:44:12 +0200
committerKarel Kočí <karel.koci@nic.cz>2016-09-12 08:44:12 +0200
commit8bd48bae75cf738ae9127b770515836a3a60d7e2 (patch)
treea1ed1fc52911a17c68d08d148c00ba2836136750 /zshrc
parente580bd60607f2a4420eacd681ec029c8b3838953 (diff)
downloadmyconfigs-8bd48bae75cf738ae9127b770515836a3a60d7e2.tar.gz
myconfigs-8bd48bae75cf738ae9127b770515836a3a60d7e2.tar.bz2
myconfigs-8bd48bae75cf738ae9127b770515836a3a60d7e2.zip
Add long running bell to zsh
Diffstat (limited to 'zshrc')
-rw-r--r--zshrc39
1 files changed, 37 insertions, 2 deletions
diff --git a/zshrc b/zshrc
index 4bfbc9e..b9c68d1 100644
--- a/zshrc
+++ b/zshrc
@@ -1,3 +1,7 @@
+source ~/.shellrc
+
+[[ -o interactive ]] || return # skip on initialization if not interactive
+
zstyle ':completion:*' completer _expand _complete _ignored _approximate
zstyle ':completion:*' insert-unambiguous true
zstyle ':completion:*' max-errors 3
@@ -48,7 +52,40 @@ if [ -e ~/.local/git-prompt.sh ]; then
export GIT_PS1_DESCRIBE_STYLE="branch"
RPROMPT=$RPROMPT'$(__git_ps1 "%s")'
fi
+# 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
+ lrbell_message="`pwd`: $1"
+ if [ -n "$DISPLAY" ]; then
+ 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
################################################################
case "$TERM" in
xterm*|*rxvt*)
@@ -60,5 +97,3 @@ case "$TERM" in
}
;;
esac
-
-source ~/.shellrc