Skip to content

Instantly share code, notes, and snippets.

@logic
Created March 11, 2017 22:32
Show Gist options
  • Save logic/d034a3bba1fd33529d952342aaca5e3c to your computer and use it in GitHub Desktop.
Save logic/d034a3bba1fd33529d952342aaca5e3c to your computer and use it in GitHub Desktop.
terminal command-completion notifications from inside tmux
# Like gnome-terminal's command-completion notifications, but usually run
# everything within a tmux window? No problem: add this to your .bashrc, and
# make sure `xdotool` is installed. Adjust the `notify-send` command line to
# taste.
#
# THIS DOESN'T WORK WITH WAYLAND. If you're on Wayland, let me know if you
# come up with a reliable way to identify the currently-focused window.
function notify_finished() {
# If we're not in tmux, fall back to gnome-terminal's notification.
[[ -z $TMUX_PANE ]] && __vte_prompt_command && return
# On Xorg, gnome-terminal and others make WINDOWID available to shells,
# which we can compare to the active window to see if focus is elsewhere.
if [[ $WINDOWID != $(xdotool getactivewindow) ]]
then
local hist
hist="$(history 1)"
notify-send -a 'bash' -i utilities-terminal \
'Command completed' "${hist:7}"
fi
}
PROMPT_COMMAND="notify_finished"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment