I want to use tmux or screen automatically after ssh. I wrote some code in .ss/config which helps me with this.
# ~/.ssh/config
Match exec "[[ $(ps h o args p $PPID | wc -w) -eq 2 ]]"
RemoteCommand SESSION_NAME="debek"; tmux a -t ${SESSION_NAME} || tmux new -s ${SESSION_NAME} || screen -r ${SESSION_NAME} || screen -S ${SESSION_NAME}
RequestTTY yes
For now, there is one problem. If I want to connect to the same server from a second terminal on my local computer this obviously attach me to the same session name "debek".
I can do SCREEN_NAME="debek-{RANDOM}"
for a unique session name to work around this but when I, for example, lost my connection and try to connect again it will create me a new session name instead connect to my last one automatically.
Have you got any idea how to resolve this problem?