Back to: All Forums  tmux  Automating tmux
05 Jun 2013, 14:24
Generic-user-small

Diederik de Haas (4 posts)

Hi,

My system: Debian Sid (64-bit), ruby 1.9.1 (no ‘rvm’), tmux 1.8, tmuxinator 0.5.0 (installed with ‘gem install tmuxinator’)

I had written a whole story about how I tried to use tmuxinator, but trying to recreate my issue I got different results each time I did it, so I’ve now abandoned it. I really liked the idea of ‘pre:’ (per tab even, see https://github.com/aziz/tmuxinator/blob/master/lib/tmuxinator/assets/sample.yml) a lot, but the first time it worked to a certain extend (and I wanted to ask how to fix the issues), but in subsequent tries, it didn’t work at all.

So now I’m back to the ‘traditional’ way of automating tmux. Here is my ‘pydev’ command I created:

tmux new-session -s python -n interactive -d
tmux send-keys -t python:interactive 'cd ~/dev/python' C-m
tmux send-keys -t python:interactive 'python' C-m
tmux split-window -h -t python:interactive
tmux send-keys -t python:interactive.2 'python' C-m
tmux send-keys -t python:interactive.2 'help()' C-m

tmux new-window -n pyOwnCloud
tmux split-window -h -p 45 -t python:pyOwnCloud
tmux split-window -v -p 70 -t python:pyOwnCloud.2
tmux send-keys -t python:pyOwnCloud.1 'cd ~/dev/owncloud/pyOwnCloud' C-m
tmux send-keys -t python:pyOwnCloud.2 'cd ~/dev/owncloud/pyOwnCloud' C-m
tmux send-keys -t python:pyOwnCloud.3 'cd ~/dev/owncloud/pyOwnCloud' C-m
tmux send-keys -t python:pyOwnCloud.2 'ls' C-m
tmux send-keys -t python:pyOwnCloud.3 'git status' C-m
tmux select-pane -t python:pyOwnCloud.1

tmux select-window -t python:interactive
tmux select-pane -t python:interactive.1
tmux attach -t python

My questions: 1. Is there a way to ‘cd ' for a window so that when I create another pane in that window, it will be in that same directory? With the following code snippet it only changes to in 1 pane:

tmux new-window -n pyOwnCloud
tmux send-keys -t python:pyOwnCloud 'cd ~/dev/owncloud/pyOwnCloud' C-m
tmux split-window -h -p 45 -t python:pyOwnCloud
tmux split-window -v -p 70 -t python:pyOwnCloud.2

But when you start tmux up ‘normally’, do ‘cd ' and then create a new pane, that new pane with also be in the changed directory.

  1. It looks like tmux is echoing the commands before it executes them. Is there a way to suppress that? Example (for python:pyOwnCloud.3 pane):
cd ~/dev/owncloud/pyOwnCloud
git status
diederik@bagend:~$ cd ~/dev/owncloud/pyOwnCloud
diederik@bagend:~/dev/owncloud/pyOwnCloud$ git status
18 Jun 2013, 02:21
Bphogan_pragsmall

Brian P. Hogan (145 posts)

For question 1, the split-window takes the -c option to specify the directory.

tmux new-session -s web -n vim -d
tmux send-keys -t web:vim 'cd tmp' C-m
tmux split-window -h -t web:vim -c ~/tmp
tmux attach -t web

For question 2, because you are using send-keys, it will absolutely echo those to the screen. It’s acting as if you typed them. What you could do is simply issue the clear command after each command you do:

tmux send-keys -t web:vim 'cd tmp; clear' C-m

Does that help?

Great questions! Thanks!

18 Jun 2013, 08:29
Generic-user-small

Diederik de Haas (4 posts)

The ~c parameter is quite useful and cleaned my script up nicely, thanks.

The clear command did help, but a bit too much in my case, which I’ve solved by using ‘echo “”’ LOL. You said because you are using send-keys which indicates there’s another solution for it. If so, which?

Current script code:

tmux new-session -s python -n interactive -d
tmux send-keys -t python:interactive 'cd ~/dev/python; clear' C-m
tmux send-keys -t python:interactive 'python' C-m
tmux split-window -h -t python:interactive -c '~/dev/python'
tmux send-keys -t python:interactive.2 'clear; python' C-m
tmux send-keys -t python:interactive.2 'help()' C-m

tmux new-window -n pyOwnCloud -c '~/dev/owncloud/pyOwnCloud'
tmux split-window -h -p 45 -t python:pyOwnCloud -c '~/dev/owncloud/pyOwnCloud'
tmux split-window -v -p 70 -t python:pyOwnCloud.2 -c '~/dev/owncloud/pyOwnCloud'
tmux send-keys -t python:pyOwnCloud.2 'clear; echo "ls `pwd`"; ls' C-m
tmux send-keys -t python:pyOwnCloud.3 'clear; echo "git status"; git status' C-m
tmux select-pane -t python:pyOwnCloud.1

tmux select-window -t python:interactive
tmux select-pane -t python:interactive.1
tmux attach -t python
  You must be logged in to comment