Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I do want to use tmux by default when I am establshing ssh connection and this works well with a command like:

ssh host.example.com -t 'tmux a || tmux || /bin/bash'

I can even put this as part of the ProxyCommand inside the ~/.ssh/config but the problem is that I am also doing SSH connections as part of scripts that are just running different commands on the remote machines and I do not want tmux in this case.

How can I achieve this behaviour so tmux invocation would be transparent and happen only when ssh is colled without any paramerts / commands.

share|improve this question

2 Answers 2

Solved by adding this to ~/.bashrc:

function ssh() {
  if [ "$#" == "1" ]; then
    if [ "${1:0:1}" != "-" ]; then
      /usr/bin/ssh "$@" -t 'tmux a || tmux || /bin/bash'
    else
    /usr/bin/ssh "$@";
    fi
  else
    /usr/bin/ssh "$@";
  fi
}
share|improve this answer

You're re-inventing the wheel.

  • Install Byobo.
  • byobu-enable
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.