Show HN: Alert yourself after a long-running task in terminal
gist.github.com
gist.github.com
Probably is a bit of a 'hacky' way, and using different proprietary services (heroku and discord) but it works, does it fine, and it's free! (And it was also funny and quick to develop by myself).
The source code is on Github too! https://github.com/TrianguloY/ping
I think the repo is private though.
I also made a similar service in the past for Heroku webhooks, to be notified with heroku apps status. Github already have one built-in. https://github.com/TrianguloY/webhook-discord
Webhooks are a really interesting feature!
But personally I made it for two reasons: no need to know the discord webhook api (a long alphanumeric url) nor the json required, so I can use it wherever I want without having to remember almost anything; and as a url to be able to use it from any internet-connected thing, not only with curl, even the browser if you want.
[0] https://github.com/sheagcraig/yo [1] https://cgamesplay.com/post/2020/12/09/iterm-notifications/
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=795774
VTE Patch: https://src.fedoraproject.org/rpms/vte291/raw/623150318ddb9a...
gnome-terminal Patch: https://src.fedoraproject.org/rpms/gnome-terminal/raw/bb5f88...
function postexec_notify --arg cmd --on-event fish_postexec
set -l s $pipestatus
if test "$CMD_DURATION" -ge 25000 && ! string match -rq '(^man|\s--help)(\s|$)' $cmd
if string match "$status" -qv 0 $s
terminal-notifier -title $cmd -message 'Exited with '(string join '|' $s)' after '(math $CMD_DURATION / 1000)s
else
terminal-notifier -title $cmd -message 'Finished in '(math $CMD_DURATION / 1000)s
end
end
end
As a bonus, this includes the command line in the notification.I found that this can be somewhat annoying when reading man pages or interactive content though. To remedy this, I tried detecting whether the terminal is focused at the time of command completion, but it doesn't seem possible to get the terminal's pid from fish. The pid of the topmost application can be retrieved with:
osascript -e 'tell application "System Events" to return unix id of (first process whose its frontmost is true)'I combine it with the timer plugin to print how long the command takes to complete.
I'd argue that most developers should become familiar with ohmyzsh, it has a bunch of useful plugins. My favorites being fzf, git, timer and bgnotify, and I love that tiny green arrow that tells you if the last command was successful.
`some_task && noti`
`noti some_task`
both work.
- Using a zsh plugin, it works for every command that I run, but only if I need it, so it doesn't create extra noise. Meaning, it is automatically activated for terminals that go out of focus. I don't need a special suffix to activate it. I recently contributed a tmux pull request just for that [1].
- It's a fixed size, flashing window in a side monitor, so if I got off the chair after execution started, I still notice the termination when I return to my workstation.
- If I change my focus back to the unfocused terminal where the termination happened, the notification disappear by itself (no extra action needing to click the 'x'!).
- It contains information regarding the tmux pane in which the termination has happened. This is needed, because I have multiple tmux sessions each having multiple windows with multiple panes in it, and all this on top of multiple XFCE workspaces.
- It's a server-client architecture, so clients running on separate host shells can run on a different computer and am able to send over termination notifications to the server that hosts the GUI (my workstation desktop).
My solution is usually as follows:
$ long-running-command; open song.mp3 sleep 2 && notify-send "Done"notify-send can be installed with the ruby-notify package.
On cygwin/win10, I have an alias for 'wakeme', which under the hood uses Snoretoast, then I just append '; wakeme' to the command I run.
alias wakeme='date && /cygdrive/c/tools/snoretoast/snoretoast.exe -t "hello" -m "wake up" -p "C:\Dropbox\tools\mindblown.png" -s "ms-winsoundevent:Notification.Reminder"'
1. Scanned for patterns in these logs periodically.
2. Send out a mail to my Gmail account with specific subjects.
3. I had set up IFTTT[1] on my mobile (android) to scan my inbox and look for certain subject lines^, and trigger playing music.
Worked like a charm for the ~6 months I was on the project.
^ Maybe bodies too, can't remember now, this was in 2015-2016.
EDIT: I should also note this workflow encouraged quite a bit of fun social interaction. My team knew of this setup, and when my phone would randomly play music, everyone would break into laughter as I hurried back to my desk to troubleshoot!
osascript -e "display notification \"Alert\""ps: maybe sem-related: for things that I want to run a long time ad want them to use less cpu while they do for whatever reason (like overheating), I wrote a bash script I called "verynice" that makes everything in the same process group as the program it executes, all go to sleep for N seconds, then wakes/runs them again for M seconds afterward, in a loop. And when it finishes, (ie, the sleep/wake target not running any more), it exits. Then the typeahead noted above could finally execute and beep or pop up a message.
For WSL users, you can substitute a powershell call to BurntToast[2]
[1]https://gitlab.com/victor-engmark/tilde/-/commit/1fc8b9f6ab0...
say “Build Done” spd-say "Build Done" npm i && say 'done installing. back to work now'Example:
./some_script.sh; curl https://nudge.sh/YOUR_TOKEN
Just need to register your phone number at nudge.sh to get a token (don’t worry, your data is safe and not shared with anyone or used for any other purpose)
Running it on DEBUG so it covers all commands is an interesting idea. I'm not sure I'd want alerts on things like exiting vim/less though. I don't suppose there's some nifty heuristic for whether programs accept user input?
[0] [link redacted]
(actually do the keystrokes) works for me in a pinch