Created
March 23, 2012 00:40
-
-
Save nyarly/2165845 to your computer and use it in GitHub Desktop.
Vim + TMux work
This file contains 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 characters
#!/bin/bash | |
if [ $# -lt 1 ]; then | |
echo "Usage: $0 <cmd>" | |
exit 17 | |
fi | |
session_idx=$(tmux display -p "#S") | |
window_idx=$(tmux display -p "#I") | |
pane_idx=$(tmux display -p "#P") | |
awk_script='/^[^[:space:][:digit:]]/ && /^Session/ { in_sessions = 1; next } | |
/^[^[:space:][:digit:]]/ && !/^Session/ { in_sessions = 0} | |
in_sessions == 1 && /^ {0,1}'$session_idx':/ { print "Session"; in_session = 1 } | |
/^[ [:digit:][[:digit:]]/ && !/^ {0,1}'$session_idx':/ { in_session = 0 } | |
in_session == 1 && /^ {2,3}'$window_idx':/ { print "Window: "; in_window = 1 } | |
/^ {2}[ [:digit:][[:digit:]]/ && !/^ {2,3}'$window_idx':/ { in_window = 0 } | |
in_window == 1 && /^ {4,5}'$pane_idx':/ { in_pane = 1 } | |
/^ {4}[ [:digit:][[:digit:]]/ && !/^ {4,5}'$pane_idx':/ { print "Pane"; in_pane = 0 } | |
in_sessions == 1 && in_session == 1 && in_window == 1 && in_pane == 1 { print $3 }' | |
pid=$(tmux server-info | awk --posix "$awk_script") | |
if [ -z $pid ]; then | |
echo "Couldn't find $session_idx:$window_idx:$pane_idx" | |
exit 27 | |
fi | |
dir=$(readlink /proc/$pid/cwd) | |
cd $dir | |
exec $@ |
This file contains 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 characters
bind-key v command-prompt -p file: 'run-shell "~/bin/tmux-locate ~/bin/vim-window %%"' |
This file contains 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 characters
#!/bin/bash | |
if [ $# -lt 1 ]; then | |
echo "Usage: $0 <file> [name] [line]" | |
fi | |
filename=$1 | |
if [ $# -lt 2 ]; then | |
title=$(basename $filename) | |
else | |
title=$2 | |
fi | |
vimcmd="vim $filename" | |
if [ $# -ge 3 ]; then | |
vimcmd="vim +$3 $filename" | |
fi | |
tmux new-window -n $title "$vimcmd" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment