TMUX: detaching other connection

Under cut a shell script to detaching all connection, except current.

It might be helpful when you using tmux at work and at home, but monitor resolutions are different and you forgot to detach any other tmux clients.

Here’s the code:

$ cat ~/bin/ #!/bin/bash TTYCUR="$(tmux display-message -p "#{client_tty}" | sed 's|/|\\/|g')" if [ -z "$TTYCUR" ]; then echo "Should be runned inside tmux session" exit 1; fi #tmux list-sessions OTHERTTY=( $( tmux list-clients | sed "/^${TTYCUR}:/d; s/^\([^:]\+\):.*$/\1/" ) ) for t in ${OTHERTTY[@]}; do # echo "$t" kill $(ps -t "$t" -o "pid" | sed '1d') done

Now inside any tmux session will be enough to run bash ~/bin/ to drop any other attached connection.


Leave a Reply

Your email address will not be published. Required fields are marked *