How do I run a shell command from .tmux.conf
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"
.
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'
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:
#!/bin/sh
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.