Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alert in tmux when a process completes

Tags:

tmux

Can I set tmux to trigger an alert in a non-active window when a process completes?

For example: I start a long build process. I would like to be notified when it completes, not each time it prints a status.

like image 738
John Avatar asked May 20 '14 08:05

John


2 Answers

I'm surprised this answer hasn't been given yet: You can use the tmux window setting visual-bell for this. With bell-action you can then configure whether you want to see bells for the current window only, or for non-current window only (other). Personally I prefer the second, as you won't see noise generated by the shell, and you probably don't care about the notification if it's in the current window.

set-window-option -g visual-bell on set-window-option -g bell-action other 

When a process generates a bell, tmux will highlight the the title of the window that rings the bell as well as show a "Bell in window X" notification.

Then ring the bell at the end of the process. E.g.:

make; echo -e '\a' 

(or && || instead of ; if you want to ring only on success or failure respectively)

like image 94
wump Avatar answered Sep 28 '22 08:09

wump


There 3 solutions I know, none really ideal. You may put those commands in your ~/.tmux.conf or just run them directly as Tmux command via Ctrl-B :.

  1. Monitor and alert whenever the output changes (you may then redirect output somewhere else so that output changes only after the command is complete):

    :set -g visual-activity on :setw -g monitor-activity on 
  2. Monitor and alert whenever the output did not change for a while (30 seconds here):

    :set -g visual-silence on :setw -g monitor-silence 30 
  3. (deprecated and someday replaced by a better option) Monitor and alert whevener the output contains a string matching given pattern (and possibly run your command like my-command; echo foobar):

    :set -g visual-content on :setw -g monitor-content foo*bar 
  4. $ some-command; tmux display-message "Task 1 done". However the message will only show for a short duration defined via :set -g display-time 4000.

If you keep the visual-* to off (default), it'll only highlight the name of the window in which the alert occurred without showing a global alert status message.

For details about each of these settings, see tmux man page

Updated (thanks for Steven Lu)

like image 40
Wernight Avatar answered Sep 28 '22 09:09

Wernight