Personally I have a flask app deployed on heroku that posts a message to a Discord webhook just by visiting an url. So in my case when I use ssh to run long tasks I have at the end "curl https:// <server> .herokuapp.com/?Finished" and as soon as that commands is executed I receive a message either at my phone or computer (through a channel in a personal discord server).
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).
I guess so, the app is simply a middleware and if you check the source code it is basically a fetch to the discord api url with the specific json it needs.
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.
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
I hear that `terminal-notifier` is pretty much dead and a better replacement with new MacOS APIs is [0]. In any case, I opted against it because iTerm actually supports this natively, in addition to a few other neat features, and it will work over SSH. I wrote about my solution here [1].
There is a native feature for this however gnome-terminal won't ship it largely due to disagreement how to integrate it with shells. However Fedora includes patches for it and I use it every day and it is amazing. The best thing about the native integration is that it notifies for every command completion where the terminal isn't focused. This means that when I am watching the terminal I don't get distracting notifications at the top of my screen and closing vim or less even if it has been open for a while doesn't trigger it either. The time based approach is just not as good as you may miss short commands (especially unexpectedly short, so you switch away because you think it will take a while then are confused when you don't see the notification you expected) and get bothered unnecessarily when you are looking at the terminal.
Here is it for fish, using the postexec event handler:
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 use ohmyzsh with the bgnotify plugin that does the same.
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.
wow, I didn't know this, thanks for the info. Sometimes it happens that I run something and after 30 minutes think "Hmm, would have been great to add noti"
I've recently coded something like this, however with significant differences from what OP is presenting. Here are the most important differences:
- 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).
I wrote Notica (https://notica.us) to do something similar. It uses web browser notifications so it works on the servers you are SSH'd into and also to your phone.
The dialog box from notify-send can be customized using facilities of the DE. I happen to use it with XFCE, and customization is then under "Notifications".
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!
I just typeahead something to give a beep or popup with text, like with a little script. :) Seems others here all have their own way to do similarly.
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.
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)
Ah, I have something like this just for `make`[0], which I've found very useful.
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?
For what it's worth, Starship also does this(https://starship.rs/config/#command-duration), with the possibility to only trigger notifications for tasks running more than N seconds.
This is great. Wanted to something about this for a long time. There are more features I desire: notify me when some string pattern occurs in the log. Also I tend to walk away from desk when I run a long program. So sometimes I'd prefer more aggressive notifications such as calling my cell.
Konsole lets you turn on notifications after X seconds of activity or X seconds of inactivity, and these two options are conveniently accessible in the Show menu. I just noticed that there is also a "Monitor for Process Finishing", this must be new :-)
Some time ago I also played around with notifications when a long running task occasionally stopped for user input (like apt-get). I had some LD_PRELOAD hack that worked ok, hooking into read calls. I probably lost it, it would be nice to rediscover it again.
My personal favorite method was to have a script sms me at the end of a long running task with the status code, last few lines if any error and how long it took to run.
For Linux equivalents, there’s Dunst with libnotify. If you want to walk away from your computer and want a notification to your phone, Pushover is great
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