Skip to content

Instantly share code, notes, and snippets.

@v-lopez
Forked from xim/bashrc.append
Last active August 29, 2015 14:03
Show Gist options
  • Save v-lopez/1bebf0159fa335853d21 to your computer and use it in GitHub Desktop.
Save v-lopez/1bebf0159fa335853d21 to your computer and use it in GitHub Desktop.
# vim file:34 otherfile:1337 -> Open files at respective lines. And in tabs!
vim() {
declare -a args
let fcount=0
hit_dashdash=
for arg in "$@" ;do
if [[ "$arg" =~ ^- && ! "$hit_dashdash" ]] ;then
args+=("$arg")
[[ "$arg" = "--" ]] && hit_dashdash=1
continue
fi
let fcount+=1
if [[ "$arg" =~ : && -e `echo $arg | cut -d: -f1` && `echo $arg | cut -d: -f2` =~ ^[0-9]+*$ ]] ;then
args+=(`echo $arg | cut -d: -f1`)
lines[$fcount]=`echo $arg | cut -d: -f2`
else
args+=("$arg")
fi
done
script=$'tab all\ntablast\n'
while [[ $fcount -gt 0 ]] ;do
script+="${lines[$fcount]}"$'\n'
let fcount-=1
[[ $fcount -gt 0 ]] && script+=$'tabprev\n'
done
`type -P vim` -S <(echo "$script") "${args[@]}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment