Skip to content

Instantly share code, notes, and snippets.

@originalsouth
Created May 22, 2017 10:55
Show Gist options
  • Save originalsouth/77d7ca7c10f81087a9bd1a3c45ceb3c3 to your computer and use it in GitHub Desktop.
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
#!/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