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.

How do I run a shell command from .tmux.conf, or otherwise automatically when tmux launches, without having to hit any other command?

How can I create an alias, a function, or a script which boils down to, for example

tmuxirc -> tmux + irssi

share|improve this question
    
See also unix.stackexchange.com/questions/61386/… –  jasonwryan Jun 24 '13 at 7:18

3 Answers 3

up vote 6 down vote accepted

It sounds like you want to externally invoke tmux from your shell rather than doing this from within tmux, so .tmux.conf is the wrong place. You can use a shell alias (place this in your .bashrc for reuse):

alias tmuxirc='tmux new-session -s irc irssi'
share|improve this answer
    
I use zsh, but otherwise 100% correct. –  Emanuel Berg Jun 24 '13 at 19:22

I do something similar with a script. When I want to fire up tmux with my development configuration I call it. The script itself looks like the following:

tmux has-session -t development
if [ $? != 0 ] then
    tmux new-session -s development -n editor -d
    tmux send-keys -t development 'cd /var/www/htdocs/' C-m
    tmux send-keys -t development 'vim' C-m
    tmux split-window -v -t development
    tmux split-window -v -t development
    tmux select-layout -t development main-horizontal
    tmux send-keys -t development:0.1 'cd /var/www/htdocs/' C-m
    tmux new-window -n console -t development
    tmux send-keys -t development:1 'cd /var/www/htdocs/' C-m
    tmux select-window -t development:0
fi
tmux attach -t development

What this gives me is a tmux session with 2 windows, window 1 has a Vim session in the top of the screen, with two terminals in the bottom 3rd or so of the screen, all pointed at my /var/www/htdocs/ directory. Window 2 is just a full screen console. Good thing about this is that it won't recreate the session if it's already there, it will just attach to it.

share|improve this answer
    
You might want to look at tmuxinator. –  Chris Down Jun 25 '13 at 3:14

While it doesn't seem to be what you were looking for, the solution to:

How do I run a shell command from .tmux.conf

is run-shell, or, in its abbreviated form, run. From the tmux man page:

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

If you need to silently kick off a script in the background whenever you launch tmux, you could use run "command > /dev/null".

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.