Shell Script

note-after.sh to Get Notifications in Linux

2018-03-22 06:15:00 +0000
Linux, Notification

tl;dr

#!/usr/bin/sh
# Written by Don Kim (dgkimdev@gmail.com)
#
# It executes whole arguments and pops a notification after finished.
# Since it uses notify-send, libnotify is required.

dowork() {
	echo "$*"
	"$@"
}
notesuccess() {
	notify-send "DONE" "$*" -a "noteafter"
}
notefailure() {
	notify-send "FAILED" "$*" -a "noteafter" -u "critical"
}

{
	dowork "$@" && notesuccess "$@"
} || {
	notefailure "$@"
}

Of course, I use it abbreviated as na sudo pacman -Syyuu via an alias.

My other scripts and configuration files are on my Github repository.

Motivation: the rust program alert-after

I happened to find this project, which delivers a desktop notification after a command finishes executing. It supports Linux, MacOS, and Windows.

Although this program looks good to me, I just don’t want the support for MacOS and Windows. So I wonder how to get the same but minimal functionality for my Linux environment, and the conclusion is that the shell script is enough to do this. Today I learned that

Those were all I needed to implement the functionalities.

References