zshrc.d/30-functions-tmux.zrc
changeset 32 0df5ad40ffb9
parent 31 c293e65d905f
child 33 1400f5ed243c
equal deleted inserted replaced
31:c293e65d905f 32:0df5ad40ffb9
    40         fi
    40         fi
    41     fi
    41     fi
    42 
    42 
    43     echo "No terminal multiplexer session found."
    43     echo "No terminal multiplexer session found."
    44 }
    44 }
       
    45 
       
    46 
       
    47 # From http://stackoverflow.com/questions/7814612/is-there-any-way-to-redraw-tmux-window-when-switching-smaller-monitor-to-bigger
       
    48 # A big thank-you to Chris Johnsen for this one.
       
    49 # (Code slightly modified - Mikael)
       
    50 function tmux_takeover() {
       
    51     # create a temporary session that displays the "how to go back" message
       
    52     tmp='takeover_temp_session'
       
    53     if ! tmux has-session -t "$tmp" >/dev/null 2>&1; then
       
    54         tmux new-session -d -s "$tmp"
       
    55         tmux set-option -t "$tmp" set-remain-on-exit on >/dev/null
       
    56         tmux new-window -kt "$tmp":0 \
       
    57             'echo -e "\nUse Prefix + L (i.e. ^B L) to return to session."'
       
    58     fi
       
    59 
       
    60     # switch any clients attached to the target session to the temp session
       
    61     session="$1"
       
    62     for client in $(tmux list-clients -t "$session" -F '#{client_tty}'); do
       
    63         tmux switch-client -c "$client" -t "$tmp"
       
    64     done
       
    65 
       
    66     # attach to the target session
       
    67     tmux attach -t "$session"
       
    68 }