Skip to content

Instantly share code, notes, and snippets.

@jonbartlett
Last active May 7, 2018 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonbartlett/faf43c9535dfe6a3ae8b89075e48e200 to your computer and use it in GitHub Desktop.
Save jonbartlett/faf43c9535dfe6a3ae8b89075e48e200 to your computer and use it in GitHub Desktop.
Notification script
#!/bin/bash
# Send a tmux, desktop, and audio notification after the completion
# of the given command when using tmux.
#
# Requires: tmux
# Recommended: espeak, libnotify
#
# modified version of https://gist.github.com/thewtex/4969741
#
# added:
# tmux colour
# pushover
#
# get tmux window the command was initiated from
tmux_window=$(/usr/local/bin/tmux list-windows \
-F "#{window_active} #{window_index} #{window_name}" | \
sort | tail -n 1 | cut -d ' ' -f 2-)
# define notification content
notification="Notify >> $@ in ${tmux_window}"
# execute command
"$@"
# set notification content on exit status
if test $? -eq 0; then
notification="${notification} succeeded"
tmux set message-bg colour150 > /dev/null 2>&1
tmux set message-fg black > /dev/null 2>&1
else
tmux set message-bg colour174 > /dev/null 2>&1
tmux set message-fg black > /dev/null 2>&1
notification="${notification} failed"
fi
# send notifications
/usr/local/bin/tmux set-option display-time 3000 > /dev/null 2>&1
/usr/local/bin/tmux display-message "${notification}"
# notify-send
if which notify-send &> /dev/null; then
notify-send "${notification}"
fi
# espeak
if which espeak &> /dev/null; then
espeak "${notification}"
fi
hostname=$(hostname)
# pushover
curl -s \
--form-string "token=a1ys2xv75e2g71mdti7xmqqkrfmwp4" \
--form-string "user=uem2v4bm6b67x2gq3vrxrx8n1uouyi" \
--form-string "message=${hostname}: ${notification}" \
https://api.pushover.net/1/messages.json &> /dev/null
@jonbartlett
Copy link
Author

clone rep then symlink to /usr/bin/notify

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