Skip to content

Instantly share code, notes, and snippets.

@nyarly
Created March 23, 2012 00:40
Show Gist options
  • Save nyarly/2165845 to your computer and use it in GitHub Desktop.
Save nyarly/2165845 to your computer and use it in GitHub Desktop.
Vim + TMux work
#!/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 $@
bind-key v command-prompt -p file: 'run-shell "~/bin/tmux-locate ~/bin/vim-window %%"'
#!/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