-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
kdialog --title "$cmd_basename completed" --passivepopup ""$cmd" took $cmd_time seconds"
to use at KDE without notify-tools installed.
PS Thanks a lot!