small medium large xlarge

Back to: All Forums  tmux
11 Jan 2015, 07:27
Michael Tippie (2 posts)

Hi everyone, sorry if this is a silly question. I’m still new to using TMUX.

I’m looking for a way for TMUX to execute a command when it’s opened for the first time - EG, I type “tmux” (or it loads automatically) and somehow TMUX then executes the “hello_world” binary I have in my local directory, displaying “Hello, world!” in the TMUX window.

Can I do this from the TMUX config file somehow?

Thanks in advance.

13 Jan 2015, 06:57
Michael Tippie (2 posts)

After a post on SuperUser, I figured this out.

Tmux runs /root/.bashrc when it opens a terminal, same as when you initially log in. So, /root/.bashrc actually gets run twice if you log in and then run tmux.

I just wrote an if statement in .bashrc to check if tmux is running or not, and also to check for the presence of a file to see if it has executed “for the first time” or not:

if [[ -n "$TMUX" ]] && [[ ! -e "/root/.automatic_start_done" ]];then
    #Make sure this doesn't happen more than once
    touch /root/.automatic_start_done
    #Now actually do the thing I want done on first startup: