Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Displays a notification when a command, that takes over 10 seconds to execute, finishes and only if the current window isn't the terminal. Add to your .zshrc: [ -e path/to/notifyosd.zsh ] && . path/to/notifyosd.zsh
function active-window-id {
echo `xprop -root | awk '/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}'`
}
# end and compare timer, notify-send if needed
function notifyosd-precmd() {
if [ ! -z "$cmd" ]; then
cmd_end=`date +%s`
((cmd_time=$cmd_end - $cmd_start))
fi
if [ ! -z "$cmd" -a $cmd_time -gt 10 -a "$window_id_before" != "$(active-window-id)" ]; then
notify-send -i utilities-terminal -u low "$cmd_basename completed" "\"$cmd\" took $cmd_time seconds"
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() {
window_id_before=$(active-window-id)
cmd=$1
cmd_basename=${cmd[(ws: :)1]}
cmd_start=`date +%s`
}
# make sure this plays nicely with any existing preexec
preexec_functions+=( notifyosd-preexec )
@DAP-DarkneSS

This comment has been minimized.

Copy link

@DAP-DarkneSS DAP-DarkneSS commented Mar 28, 2013

kdialog --title "$cmd_basename completed" --passivepopup ""$cmd" took $cmd_time seconds"
to use at KDE without notify-tools installed.
PS Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment