Created
May 22, 2017 10:55
-
-
Save originalsouth/77d7ca7c10f81087a9bd1a3c45ceb3c3 to your computer and use it in GitHub Desktop.
launch a command in the background and notify the user when it's done
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
#!/usr/bin/env zsh | |
main() | |
{ | |
START=$(date +%s) | |
STARTT="$(date)" | |
OUT="$(mktemp nm.XXXXXXXXXX)" | |
echo "the launchpath was $(pwd) with pid $$" > $OUT | |
echo "the received output is:" >> $OUT | |
if [ "$1" = "-" ] | |
then | |
cat - &>> $OUT | |
else | |
$@ &>> $OUT | |
fi | |
echo "------\nend of message" >> $OUT | |
SUB="Launch '$@' is done! -- $(date)" | |
SEDEXP='1i "'$@'" was launched by launched by "'$(whoami)@$(hostname)'" on "'$STARTT'" ran for '$(($(date +%s)-$START))'s' | |
sed -i "$SEDEXP" $OUT | |
notify-send --urgency=critical "$SUB" "$(tail --bytes 1024 $OUT)" | |
rm -f $OUT | |
} | |
if [ $# -eq 0 ] | |
then | |
echo "nm: to what do I owe the extreme pleasure of this visit?" | |
else | |
main "$@" & | |
disown | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment