Skip to content

Instantly share code, notes, and snippets.

@lorf
Forked from vlad-shatskyi/notifyosd.zsh
Last active December 16, 2015 06:49
Show Gist options
  • Save lorf/5394390 to your computer and use it in GitHub Desktop.
Save lorf/5394390 to your computer and use it in GitHub Desktop.
notifyosd-init() {
if [ -n "$DISPLAY" -a -z "$notifyosd_initialized" ]; then
notifyosd_initialized=yes
function notifyosd-active-window-id {
xprop -root | awk '/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}'
}
# end and compare timer, notify-send if needed
function notifyosd-precmd() {
if [ ! -z "$notifyosd_cmd" ]; then
notifyosd_cmd_end=`date +%s`
((notifyosd_cmd_time=$notifyosd_cmd_end - $notifyosd_cmd_start))
fi
if [ ! -z "$notifyosd_cmd" -a $notifyosd_cmd_time -gt 10 -a "$notifyosd_window_id_before" != "$(notifyosd-active-window-id)" ]; then
notify-send -i utilities-terminal -u low "$notifyosd_cmd_basename completed" "\"$notifyosd_cmd\" took $notifyosd_cmd_time seconds"
fi
unset notifyosd_cmd notifyosd_cmd_basename notifyosd_cmd_start notifyosd_cmd_end notifyosd_cmd_time
}
# make sure this plays nicely with any existing precmd
precmd_functions+=( notifyosd-precmd )
# get command name and start the timer
function notifyosd-preexec() {
notifyosd_window_id_before=$(notifyosd-active-window-id)
notifyosd_cmd=$1
notifyosd_cmd_basename=${notifyosd_cmd[(ws: :)1]}
notifyosd_cmd_start=`date +%s`
}
# make sure this plays nicely with any existing preexec
preexec_functions+=( notifyosd-preexec )
fi
}
notifyosd-init
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment