Add tmux_takeover (from Chris Johnsen' S.O. post)
authorMikael Berthe <mikael@lilotux.net>
Wed, 02 Sep 2015 19:07:59 +0200
changeset 32 0df5ad40ffb9
parent 31 c293e65d905f
child 33 1400f5ed243c
Add tmux_takeover (from Chris Johnsen' S.O. post)
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"
+}