Last active
August 29, 2015 13:56
Revisions
-
ThiefMaster revised this gist
Mar 3, 2014 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,2 @@ bind '"' run-shell -b 'tmux-smartsplit v' bind % run-shell -b 'tmux-smartsplit h' -
ThiefMaster created this gist
Mar 3, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ #!/bin/bash # tmux-smartsplit # open a new tmux (split-)window which will automatically # continue the existing ssh session if one exists SIP=$(tmux display-message -p "#S:#I:#P") PTY=$(tmux server-info | egrep flags=\|bytes | awk '/windows/ { s = $2 } /references/ { i = $1 } /bytes/ { print s i $1 $2 } ' | grep "$SIP" | cut -d: -f4) PTS=${PTY#/dev/} PID=$(ps h -eao pid,tty,command --forest | awk '$2 == "'$PTS'" {print $1; exit}') CHILD=$(cat /proc/[0-9]*/stat | awk '$4 == '$PID' {print $1; exit}') NEW_WIN_CMD="" if [[ "$CHILD" != "" ]]; then NEW_WIN_CMD=$(python3.3 -c 'import shlex, sys; parts = list(filter(None, open(sys.argv[1]).read().split("\0"))); print(" ".join(map(shlex.quote, parts)) if parts[0] == "ssh" else "")' "/proc/$CHILD/cmdline") fi case "$1" in h) tmux splitw -h "$NEW_WIN_CMD" ;; v) tmux splitw -v "$NEW_WIN_CMD" ;; *) tmux neww "$NEW_WIN_CMD" ;; esac This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ bind '"' run-shell -b 'tmux-smartsplit v' bind % run-shell -b 'tmux-smartsplit h' bind c run-shell -b 'tmux-smartsplit'