Skip to content

Instantly share code, notes, and snippets.

@ruedigerp
Created October 2, 2018 08:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruedigerp/8b6204bdfd73fd693c0ef679f6d294f5 to your computer and use it in GitHub Desktop.
Save ruedigerp/8b6204bdfd73fd693c0ef679f6d294f5 to your computer and use it in GitHub Desktop.
Tmux takeover
takeover() {
# create a temporary session that displays the "how to go back" message
tmp='takeover temp session'
if ! tmux has-session -t "$tmp"; then
tmux new-session -d -s "$tmp"
tmux set-option -t "$tmp" set-remain-on-exit on
tmux new-window -kt "$tmp":0 \
'echo "Use Prefix + L (i.e. ^B L) to return to session."'
fi
# switch any clients attached to the target session to the temp session
session="$1"
for client in $(tmux list-clients -t "$session" | cut -f 1 -d :); do
tmux switch-client -c "$client" -t "$tmp"
done
# attach to the target session
tmux attach -t "$session"
}
takeover 'original session' # or the session number if you do not name sessions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment