Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

In my tmux.conf file I have it configured to open windows, name them, setup panes etc.. etc..

However one issue I have is that if one of the panes launches a command, let's say ls, then the pane closes itself after the command completes (instantly). Is there any way to prevent this behavior? Or have it drop to a normal shell after a command completes?

I am assuming that I need to start a shell -> execute command when the pane launches, but I'll be damned if I can figure out how. I have googled a bit for this problem but have come up short.

share|improve this question
add comment

2 Answers

You could use the remain-on-exit option:

set-remain-on-exit [on | off]
Set the remain-on-exit window option for any windows first created in this session. When this option is true, windows in which the running program has exited do not close, instead remaining open but inactivate. Use the respawn-window command to reactivate such a window, or the kill-window command to destroy it.

To simplify the respawning process, you might want to bind it to a key:

bind-key R respawn-window

This will ensure you aren't left with dead windows when the programs exit.

share|improve this answer
    
I was getting there! I ran out of time and decided I'd have to edit my answer. Yes, this is the third option, the main disadvantage is that it leaves a read only window that you can't re-use without re-creating. –  Caleb Jul 21 '11 at 10:20
    
Good point. I've updated with a (semi-) workaround. –  jasonwryan Jul 21 '11 at 10:28
add comment

You have a couple of options.

  1. Instead of running ls in your window, run a shell, then send the shell keystrokes to execute:

    tmux start-server  
    tmux new-session -d -s session  
    tmux new-window -t session:1  
    tmux send-keys -t session:1 ls C-m
    
  2. You can lunch a sequence of commands in such a way as to leave yourself with a bash shell after your other commands have run:

    tmux start-server  
    tmux new-session -d
    tmux new-window 'ls;bash -i'
    
  3. See jasonwryan's answer for details on the remain-on-exit option to keep panes alive after their process has exited so you can review the output.

  4. If the output of some command was worth seeing once, it might be worth refreshing. If you are monitoring the output of something you can watch to periodically get new output. This should play nicely with panes in tmux:

    tmux start-server  
    tmux new-session -d
    tmux new-window 'watch -n 60 ls'
    
share|improve this answer
    
Thanks man! Awesome answer, number 2 and number 4 are exactly what I was working for, but number 1 seems like a great alternative as well. Thanks for all the help, it's really appreciated (both of you). –  Stew Jul 21 '11 at 12:02
    
The advantage of #1 is that the command remains in the shell history and can be easily re-executed. If the command was big and ugly, then this is very helpful. –  goertzenator Sep 17 '13 at 20:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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