6 ms·
Show HN: Alert yourself after a long-running task in terminal
- auraham 6y agoThere is an alias called alert in .bashrc in Ubuntu. You can use it as follows: sleep 3; alert
- red_hare 6y agoAnd on Mac OS: osascript -e "display notification \"Alert\""
- KMnO4 6y agoI just use printf \a for this.
- durkie 6y agoYep. "tput bel" is my version
- jcims 6y agoecho [CTRL+V][CTRL+G] (actually do the keystrokes) works for me in a pinch
- pokoleo 6y agoiTerm supports this! Take a look here: https://stackoverflow.com/questions/30016716/how-do-i-make-iterm-terminal-notify-me-when-a-job-process-is-complete https://stackoverflow.com/questions/30016716/how-do-i-make-i...
- brigandish 6y ago`A + option + command` to be alerted on the next mark, which is basically when the new prompt appears.
- onedognight 6y agoon a Mac say “Build Done”
- carbocation 6y agoon Ubuntu: spd-say "Build Done"
- inevaexisted 6y agoI do this too soo good!
- ohadron 6y agoYup. npm i && say 'done installing. back to work now'
- TrianguloY 6y agoPersonally 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:// 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). The source code is on Github too! https://github.com/TrianguloY/ping https://github.com/TrianguloY/ping
- petethepig 6y agoThis is a cool idea, I've always wanted to expand this kind of thing to other similar usecases like getting notified after long CI jobs. I think the repo is private though.
- TrianguloY 6y agoOuch, thanks for noticing, should be public now. 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 https://github.com/TrianguloY/webhook-discord Webhooks are a really interesting feature!
- yyx 6y agoI have a similar thing with telegram bot: https://pastebin.com/Ei3hjcKa https://pastebin.com/Ei3hjcKa Written in Go so it's static and portable.
- swiley 6y agoThis seems a little over complicated since curl itself could just post to discord.
- TrianguloY 6y agoI 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.
- cocoa19 6y agoI 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.
- naebother 6y agoOn Gnome (via libnotify): sleep 2 && notify-send "Done"
- jraph 6y agoThis probably works in any free desktop environment :-) notify-send can be installed with the ruby-notify package.
- cardiffspaceman 6y agoThe 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".
- l0b0 6y agoStrange how many commenters misunderstood this. This alerts when any command runs for a long time, without having to modify the command itself.
- tannercollin 6y agoI wrote Notica (https://notica.us 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.
- LordDragonfang 6y agoFor Ubuntu/Gnome users, you can substitute `notify-send` for `terminal-notifier`, as linked.[1] For WSL users, you can substitute a powershell call to BurntToast[2] [1]https://gitlab.com/victor-engmark/tilde/-/commit/1fc8b9f6ab0586499c7921b1452c43c394cd1e39 https://gitlab.com/victor-engmark/tilde/-/commit/1fc8b9f6ab0... [2]https://codelearn.me/2019/01/13/wsl-windows-toast.html https://codelearn.me/2019/01/13/wsl-windows-toast.html
- CGamesPlay 6y agoI 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]. [0] https://github.com/sheagcraig/yo https://github.com/sheagcraig/yo [1] https://cgamesplay.com/post/2020/12/09/iterm-notifications/ https://cgamesplay.com/post/2020/12/09/iterm-notifications/
- retSava 6y agoA lot of options here, so I'd like to add another :) 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"'
- tracyhenry 6y agoThis 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.
- villgax 6y agotput bel
- aarchi 6y agoHere 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)'
- aarchi 6y agoEdit: line 4 should be `if string match -qv 0 $s`.
- abhgh 6y agoReminds me of my homegrown version of a notifier. Essentially we had a lot of long running tasks that would emit logs. My terminal notifier: 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/ 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!
- mosselman 6y agoI use `noti` for this: `some_task && noti` `noti some_task` both work. https://github.com/variadico/noti https://github.com/variadico/noti
- Dowwie 6y agoYou can also use noti to watch a process id, in case you start a process but forget to append noti
- mosselman 6y agowow, 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"
- PenguinCoder 6y agoThis is great, thanks for sharing.
- steerablesafe 6y agoSome 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.
- alfiedotwtf 6y agoFor 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
- mauvehaus 6y agoOP is on Mac, which has the open command, which will open its arguments the same way they'd be opened by the Finder. My solution is usually as follows: $ long-running-command; open song.mp3
- unhammer 6y agoAh, 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? [0] https://gist.github.com/unhammer/01c65597b5e6509b9eea https://gist.github.com/unhammer/01c65597b5e6509b9eea
- meego 6y agoFor what it's worth, Starship also does this(https://starship.rs/config/#command-duration https://starship.rs/config/#command-duration), with the possibility to only trigger notifications for tasks running more than N seconds.
- kevincox 6y agoThere 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. Bug: https://bugzilla.gnome.org/show_bug.cgi?id=795774 https://bugzilla.gnome.org/show_bug.cgi?id=795774 VTE Patch: https://src.fedoraproject.org/rpms/vte291/raw/623150318ddb9a9a5797b4b9f74e6bb5d7ad7715/f/vte291-cntnr-precmd-preexec-scroll.patch https://src.fedoraproject.org/rpms/vte291/raw/623150318ddb9a... gnome-terminal Patch: https://src.fedoraproject.org/rpms/gnome-terminal/raw/bb5f88b61f68a1bb0b1f1269dfb48eabfc35b5c0/f/gnome-terminal-cntr-ntfy-autottl-ts.patch https://src.fedoraproject.org/rpms/gnome-terminal/raw/bb5f88...
- jraph 6y agoKonsole 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 :-)
- druidsbane 6y agoMy 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.
- lcall 6y agoI 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.
- st0le 6y agohttps://notify.run/ https://notify.run/
- da-x 6y agoI'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). [1] https://github.com/tmux/tmux/pull/2558 https://github.com/tmux/tmux/pull/2558
- thecodemonkey 6y agoThis looks really cool! I recently built something similar, but for notifying you via text message instead. Example: ./some_script.sh; curl https://nudge.sh/YOUR_TOKEN 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)