# HG changeset patch # User Mikael Berthe # Date 1441213679 -7200 # Node ID 0df5ad40ffb95c6eaf0d0282192b7fd7da9cc4a9 # Parent c293e65d905f0d8ebfe293ef7e0790415c6521c4 Add tmux_takeover (from Chris Johnsen' S.O. post) diff -r c293e65d905f -r 0df5ad40ffb9 zshrc.d/30-functions-tmux.zrc --- a/zshrc.d/30-functions-tmux.zrc Sun Aug 23 11:50:43 2015 +0200 +++ b/zshrc.d/30-functions-tmux.zrc Wed Sep 02 19:07:59 2015 +0200 @@ -42,3 +42,27 @@ echo "No terminal multiplexer session found." } + + +# From http://stackoverflow.com/questions/7814612/is-there-any-way-to-redraw-tmux-window-when-switching-smaller-monitor-to-bigger +# A big thank-you to Chris Johnsen for this one. +# (Code slightly modified - Mikael) +function tmux_takeover() { + # create a temporary session that displays the "how to go back" message + tmp='takeover_temp_session' + if ! tmux has-session -t "$tmp" >/dev/null 2>&1; then + tmux new-session -d -s "$tmp" + tmux set-option -t "$tmp" set-remain-on-exit on >/dev/null + tmux new-window -kt "$tmp":0 \ + 'echo -e "\nUse 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" -F '#{client_tty}'); do + tmux switch-client -c "$client" -t "$tmp" + done + + # attach to the target session + tmux attach -t "$session" +}