diff options
author | Karel Kočí <karel.koci@nic.cz> | 2016-09-12 08:44:12 +0200 |
---|---|---|
committer | Karel Kočí <karel.koci@nic.cz> | 2016-09-12 08:44:12 +0200 |
commit | 8bd48bae75cf738ae9127b770515836a3a60d7e2 (patch) | |
tree | a1ed1fc52911a17c68d08d148c00ba2836136750 | |
parent | e580bd60607f2a4420eacd681ec029c8b3838953 (diff) | |
download | myconfigs-8bd48bae75cf738ae9127b770515836a3a60d7e2.tar.gz myconfigs-8bd48bae75cf738ae9127b770515836a3a60d7e2.tar.bz2 myconfigs-8bd48bae75cf738ae9127b770515836a3a60d7e2.zip |
Add long running bell to zsh
-rw-r--r-- | shellrc | 3 | ||||
-rw-r--r-- | zshrc | 39 |
2 files changed, 40 insertions, 2 deletions
@@ -4,6 +4,9 @@ export PATH=~/.local/bin:$PATH:$(ruby -e "print Gem.user_dir")/bin export EDITOR=vim +# Continue only if this is interactive shell +[[ -o interactive ]] || return + alias ls='ls --color=auto' alias ll='ls -l' eval $(dircolors -b) @@ -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 |