I am using tmux 1.8 and did not find a built-in solution. These workarounds are suitable, at least for my general use cases:
- Capturing the contents of the full panel and searching for the last ssh command in it (I use the knowledge of completing my tooltip to find the command more or less reliably)
- If this fails, I will check the command that the panel could be created using the
shell-command parameter of the tmux new-window or split-window commands
My reconnect.sh script looks like this. The dirtiest thing about this is the way to get the latest ssh command from the buffer. So far, "> ssh" has been enough for my situations to reliably detect a string containing a request for an ssh connection, but any better solution would be appreciated.
#!/bin/bash # @TODO: change this according to your own prompt # This is used to find lines connect ssh command in the pane buffer PROMPT_SEPARATOR="> " # get current pane buffer size and dimensions HISTORY_LIMIT=`tmux display-message -p "#{history_limit}"` VISIBLE_LINES=`tmux display-message -p "#{pane_height}"` # search last ssh command in pane content LINE=`tmux capture-pane -p -J -S -$HISTORY_LIMIT -E $VISIBLE_LINES | grep "${PROMPT_SEPARATOR}ssh " | tail -1` if [ -n "$LINE" ]; then echo $LINE | sed "s/.*$PROMPT_SEPARATOR//;" else # fall back to the command that might have been used to create the pane # (not necessarily ssh but helpful anyway) tmux list-panes -F "#{pane_active} #{pane_start_command}" | grep "^1 " | tail -1 | cut -d ' ' -f2- fi
I saved this script in my ~ / .tmux directory and changed the key bindings for the various split-window and new-window shortcuts in my .tmux.conf , similar to this:
# try to reconnect to remote host when creating new window bind c run-shell 'CMD=`~/.tmux/reconnect.sh`; tmux new-window "$CMD"'
Thorsten
source share