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.
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".
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.
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].
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.
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)'
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 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 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.
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!
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"
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.
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
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.
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.
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 :-)
50 comments
[ 4.3 ms ] story [ 88.8 ms ] thread(actually do the keystrokes) works for me in a pinch
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.
notify-send can be installed with the ruby-notify package.
For WSL users, you can substitute a powershell call to BurntToast[2]
[1]https://gitlab.com/victor-engmark/tilde/-/commit/1fc8b9f6ab0...
[2]https://codelearn.me/2019/01/13/wsl-windows-toast.html
[0] https://github.com/sheagcraig/yo [1] https://cgamesplay.com/post/2020/12/09/iterm-notifications/
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"'
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:
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.
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.
[1] https://ifttt.com/
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!
`some_task && noti`
`noti some_task`
both work.
https://github.com/variadico/noti
My solution is usually as follows:
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] https://gist.github.com/unhammer/01c65597b5e6509b9eea
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...