1

I use the following tmux code in a script file tmux-dev.sh and add it to bash using bash /home/rohit/tmux-dev.sh :

tmux new-session -d
tmux split-window -h
tmux split-window -v
tmux -2 attach-session -d

The script causes a nesting of tmux panes giving error: pane too small. To my surprise , the same bash tmux-dev.sh when put into the title and command box of gnome-terminal it works perfectly fine and gives this screen screenshot

Please help me out with this.I am using ubuntu 14.10.

P.S-- Please stay away from suggesting any tools , I am here for an explanation for this behavior and raw shell script solution.

111---
  • 4,424
  • 3
  • 27
  • 50
0decimal0
  • 111
  • 6
  • So you add it to `bashrc`. I'm not experienced with `tmux`, but might it be that every new session starts its own bash shell and thus calls `.bashrc` again making it basically an endless loop? – FelixJN Aug 20 '15 at 08:42
  • @Fiximan Exactly ! each session starts its own bash shell and that's why its happening . How can I have that above tmux setting( 3 window panes ) without it to cause an endless loop. – 0decimal0 Aug 20 '15 at 09:02
  • 1
    you could change your `bashrc` to check if you are NOT in a `tmux` session before running the script: `if [ ! tmux session ] ; then bash tmux-dev.sh ; fi `. See [here](http://unix.stackexchange.com/questions/10689/how-can-i-tell-if-im-in-a-tmux-session-from-a-bash-script) for an example check. – FelixJN Aug 20 '15 at 09:15

1 Answers1

0

As @fiximan suggested , I tried to test if tmux session exists or not and then execute some code and finally, with a little tweak I am successful in getting the layout I wanted. Here is what I added to my .bashrc :

test -z "$TMUX" && (tmux new-session -d && tmux split-window -h && tmux split-window -v && tmux -2 attach-session -d)

I will break down the above for an explanation:

  1. test -z "$TMUX" -> This tests whether there is already a tmux session running or not , thus, preventing nesting of tmux sessions
  2. tmux new-session -d -> Creates a new session
  3. tmux split-window -h -> Splits the window vertically
  4. tmux split-window -v -> Splits the window horizontally
  5. tmux -2 attach-session -d-> Attaches the sessions

NOTE-- I have used && operator not the || operator because the later would short-circuit.

0decimal0
  • 111
  • 6