Created
July 25, 2012 21:09
-
-
Save Cloudef/3178694 to your computer and use it in GitHub Desktop.
vimo
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 characters
| ###################################### | |
| ## Open file inside git tree on vim ## | |
| ###################################### | |
| vimo() { | |
| local match= | |
| local gtdir= | |
| local cwd=$PWD | |
| git ls-files &>/dev/null || return # test if git | |
| gtdir="$(git rev-parse --show-toplevel)" | |
| [[ "$cwd" != "$gtdir" ]] && pushd "$gtdir" &> /dev/null # git root | |
| [[ -n "$@" ]] && { match="$(git ls-files | grep "$@")"; } || | |
| match="$(git ls-files)" | |
| [[ $(echo "$match" | wc -l) -gt 1 ]] && match="$(echo $match | dmenu -i -l 20 -p "vim")" | |
| match="$gtdir/$match" # convert to absolute | |
| [[ "$cwd" != "$gtdir" ]] && popd &> /dev/null # go back | |
| [[ -f "$match" ]] || return | |
| vim "$match" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment