Last active
June 28, 2024 03:02
-
-
Save jonbartlett/faf43c9535dfe6a3ae8b89075e48e200 to your computer and use it in GitHub Desktop.
Notification script
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
#!/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=a1ys2xv7asas5e2g71mdti7xmqqkrfmwp4" \ | |
--form-string "user=uem2v4bmsss6b67x2gq3vrxrx8n1uouyi" \ | |
--form-string "message=${hostname}: ${notification}" \ | |
https://api.pushover.net/1/messages.json &> /dev/null | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
clone rep then symlink to /usr/bin/notify