Skip to content

Instantly share code, notes, and snippets.

@vlad-shatskyi
Forked from ihashacks/notifyosd.zsh
Last active December 15, 2015 11:49
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save vlad-shatskyi/5255331 to your computer and use it in GitHub Desktop.
Save vlad-shatskyi/5255331 to your computer and use it in GitHub Desktop.
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
Copy link

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