Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###
- # Undistract-me is a shell script for Bash which shows a message when a command execution finishses.
- # I found this version (I'm not the author) to implement Undistract-me in Zsh.
- # I adapted to add a icon to notification box.
- # To use, just add this line to ~/.zshrc:
- # source <path>/undistract-me.zsh
- ###
- # commands to ignore
- cmdignore=(htop tmux top vim)
- # end and compare timer, notify-send if needed
- function notifyosd-precmd(){
- retval=$?
- if [[ ${cmdignore[(r)$cmd_basename]} == $cmd_basename ]]; then
- return
- else
- if [ ! -z "$cmd" ]; then
- cmd_end=`date +%s`
- ((cmd_time=$cmd_end - $cmd_start))
- fi
- if [ $retval -gt 0 ]; then
- cmdstat="with warning"
- sndstat="/usr/share/sounds/gnome/default/alerts/sonar.ogg"
- iconstat="error"
- else
- cmdstat="successfully"
- sndstat="/usr/share/sounds/gnome/default/alerts/glass.ogg"
- iconstat="utilities-terminal"
- fi
- if [ ! -z "$cmd" -a $cmd_time -gt 10 ]; then
- if [ ! -z $SSH_TTY ] ; then
- notify-send -i $iconstat -u low "$cmd_basename on `hostname` completed $cmdstat" "\"$cmd\" took $cmd_time seconds"
- else
- notify-send -i $iconstat -u low "$cmd_basename completed $cmdstat" "\"$cmd\" took $cmd_time seconds"
- fi
- fi
- unset cmd
- fi
- }
- # make sure this plays nicely with any existing precmd
- precmd_functions+=( notifyosd-precmd )
- # get command name and start the timer
- function notifyosd-preexec() {
- cmd=$1
- cmd_basename=${${cmd:s/sudo //}[(ws: :)1]}
- cmd_start=`date +%s`
- }
- # make sure this plays nicely with any existing preexec
- preexec_functions+=( notifyosd-preexec )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement