Skip to content

Instantly share code, notes, and snippets.

@arcusfelis
Created March 25, 2014 13:30
Show Gist options
  • Save arcusfelis/9761788 to your computer and use it in GitHub Desktop.
Save arcusfelis/9761788 to your computer and use it in GitHub Desktop.
Vim integration with tmux
#!/bin/bash
filename="$1"
basename="$(basename $1)"
curpath="$(pwd)"
cd "$(dirname $filename)"
pid="$(vim -r 2>&1 | fgrep "$basename.sw" -A 5 | grep 'still running' | sed 's/[^0-9]//g')"
cd "$curpath"
if [ -n "$pid" ]; then
tty="$(ps -p $pid -o tty h)"
window="$(tmux list-panes -s -F '#{window_id} #{pane_tty}' | grep "$tty" | cut -d ' ' -f1)"
tmux select-window -t "$window"
else
old_window_name="$(tmux list-panes -F '#{window_name}')"
tmux rename-window "_$basename"
vim "$filename"
tmux rename-window "$old_window_name"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment