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.

Can I configure tmux so it will after running tmux automatically opens two windows named src and cmd? I always type after starting it:

prefix + c, prefix + ,srcENTER

prefix + c, prefix + ,cmdENTER

I'd like to automate this.

thanks

share|improve this question

3 Answers 3

up vote 7 down vote accepted

In your particular case the following would do:

tmux new-session -n src -d \; new-window -n dst \; attach

A more general way would be to use the source-file command, e.g.

tmux new-session -d \; source-file FILE_WITH_TMUX_COMMANDS

Where FILE_WITH_TMUX_COMMANDS might contain:

rename-window src
new-window
rename-window dst
previous-window
attach
share|improve this answer
    
Thank you. Could you please explain -d option? man page says If -d is used, -x and -y specify the size of the initial window (80 by 24 if not given). and what is the purpose of attach in the end? I haven't understood it much from man pages. –  xralf May 12 '12 at 14:15
    
This will be already off topic, but would you please know why this ends with error when I run the command with -c vim? –  xralf May 12 '12 at 14:30
    
-d makes tmux start in detached mode, this was the only way I found that allows you to send additional commands to the just started tmux. The attach then attaches the current terminal to the recently started tmux. –  Thor May 12 '12 at 15:07
1  
-c vim works when it is run with tmux -c vim. For the FILE_WITH_TMUX_COMMANDS solution above, this can be done with something like send-key "vim\n". –  Thor May 12 '12 at 15:10

I'd similar need, But different.

I runs three sessions, each having different set of windows (programs) running on it.

If its adapted to your case, then

put $sh .tmuxer & in ~/.xinitrc; this will create everything for you, next time you attach to tmux, you will get what you want.

.tmuxer is a bash script with u+x privilage

#!/bin/sh                                                                                                                                             

tmux new-session -d -s default                                                                                                                     

tmux new-window -t default:1 -n 'src' '<you can give a command to run here>'                                                                                                               
tmux new-window -t default:2 -n 'cmd' 'top'                                                                                                       

tmux select-window -t default:1                                                                                                                          
tmux attach-session             

Well, this is a bit verbose, but you see how you can expand this in future to suite your evolving needs.

If you're interested, my dotFiles are hosted on github.

share|improve this answer
    
Thank you for extending correct answers. –  xralf May 13 '12 at 6:01

There's a supplemental tool called tmuxinator (found at https://github.com/aziz/tmuxinator ) that allows you to do this. I would suggest checking it out.

share|improve this answer

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.