Specifically I'm trying to give a notification after some command was completed. So, for example, if I reload my configuration file, I'd like to have some confirmation that it worked, which might be done something like this:

bind R source-file "$HOME/.tmux.conf" && display-message "Configuration reloaded."

That, however, doesn't work. Nor do any other things I tried as ways of stringing commands together.

  • 1
    It works for me (tmux 1.3 on Debian squeeze) with \; as the separator. – Gilles 'SO- stop being evil' Jun 9 '11 at 19:57
  • 1
    Okay, I found that \; does work, and that is the essence of the answer I chose below. Somehow I tested \; too quickly and determined it didn't work. But I'm leaving this question here since it still serves to answer the question of how to do this. – iconoclast Jun 9 '11 at 20:04

You could use the run-shell option, but the critical thing is to separate the commands with \;

In this case, something like:

bind R source-file ~/.tmux.conf \; run-shell "echo 'Reload'"

run-shell shell-command
(alias: run)
Execute shell-command in the background without creating a window. After it finishes, any output to stdout is displayed in copy mode. If the command doesn't return success, the exit status is also displayed.

  • Hey, thanks for the answer. I haven't tested that specifically but I don't think it will work, since I tested the code in my question with \; and it just ran the second command but not the first. And I don't know why run-shell would work but display-message wouldn't. – iconoclast Jun 9 '11 at 19:19
  • 1
    Okay, I've tried testing your solution and tmux keeps locking up, apparently (though not with absolute certainty) from that command. I'll keep trying, but I'm pretty sure it won't work... – iconoclast Jun 9 '11 at 19:53
  • It works on tmux 1.4. Does "locking up" mean "copy mode" - that is by design... – jasonwryan Jun 9 '11 at 19:54
  • okay, I got it to work, without locking up tmux. That left me with the question as to why my original attempt to use \; didn't work: – iconoclast Jun 9 '11 at 19:59
  • 1
    The heart of your answer is to use \; -- the part about run-shell is not really important, and I think for the example I gave display-message is a lot better. So I'm choosing your answer over mine, but would you mind editing the answer so it doesn't mislead or confuse other people. Thanks! – iconoclast Jun 9 '11 at 20:02

Just after composing my question I thought of something that might work. I tried it and it works, you just have to put up with multiple files for your tmux configuration.

Here's the solution, specifically as it relates to reloading your configuration. In your .tmux.conf file, put something like this:

bind R source-file "$HOME/.tmux/reload.tmux"

In the file ~/.tmux/reload.tmux put something like the following:

source-file "$HOME/.tmux.conf" 
display-message "Configuration reloaded."

It works perfectly.

  • 1
    This is actually the ONLY way it does work. Everything else here is just not working. – lzap Apr 3 '13 at 11:01
  • Really?... It's been a while since I tested the other approach, but I'd be surprised if tmux broke that. If you're absolutely sure it doesn't work, then I'll test again and possibly accept this answer instead. – iconoclast Apr 3 '13 at 17:32
  • Yeah I apologize, the above answer really does work :-) – lzap Apr 4 '13 at 10:30

Using the run-shell method puts the output into the copy buffer which requires manually clearing. Using a intermediate configuration file adds the overhead of maintaining a second configuration file. Combining both answers works better in my case, as I wanted the message to disappear after a short interval, similar to a pop-up dialog box in a GUI, but keep everything contained in a single file.

bind R source-file ~/.tmux.conf \; display-message "Configuration reloaded"

There's a patch allowing full-fledged scripting inside tmux, attaching tcl language to its internals.


Also, it allows to specify as many actions as you want for 'mode' keystrokes.

Using that, your code would look like:

bind R tcl { source-file "$HOME/.tmux.conf" ; display-message "Configuration reloaded." }

or even more readable:

bind R tcl {
  source-file "$HOME/.tmux.conf"
  display-message "Configuration reloaded."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.