3

When using tmux, I often do the following:

  • Create a new window
  • ssh to remote box
  • cd to specific dir
  • launch process

Now I want to tail the logfile of the process I just launched in a split. So I do the following:

  • Split the window
  • ssh to remote box (annoying)
  • cd to specific dir (annoying)
  • tail -f logs/run.log

What I wish was possible is to have a shortcut to split a window and automatically ssh to the same box and cd to the same dir as the parent window.

I came across the following command, which led me to believe it is possible:

bind-key S command-prompt -p ssh: "new-window -n %1 'ssh %1'"

Any idea how to achieve that?

Excellll
  • 12,847
neric
  • 161

2 Answers2

0

I came across your question many months ago and was looking for the same. I finally figured out how to accomplish part of your answer, which is the hardest part (split existing SSH). First install and configure SSHH (SSH Helper) to split the current SSH session into a new pane. Then, we can make it really fast by reusing the same ssh connection by adding this to our SSH config:

ControlMaster                  auto
ControlPath                    /tmp/ssh_mux_%h_%p_%r
ControlPersist                 4h # change to whatever you like, but 4h is a good start. 

Keep in mind that if our connection gets terminated we sometimes have to rm --force /tmp/ssh_mux_*. The tradeoff for superfast SSH splits is worth it!

Also, sshh doesn't work with Fish shell out of the box, but I figured out how to get it working, see https://github.com/yudai/sshh/issues/4.

Elijah Lynn
  • 1,602
0

I had great troubles with having everything as a one-liner, it gets confusing with the window focus and escapes for the send-keys. If you experiment a bit you could probably get it in one line.

create a tmux file

# splitssh.tmux
split-window -h   
send-keys 'ssh server' 'c-m' 'cd folder' 'c-m'
'tail -f logs/run.log' 'c-m'

bind-key S source splitssh.tmux

here's another link of the subject Binding a tmux key to multiple commands