Skip to content

Instantly share code, notes, and snippets.

@rkumar
Created December 2, 2012 14:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rkumar/4188977 to your computer and use it in GitHub Desktop.
Save rkumar/4188977 to your computer and use it in GitHub Desktop.
# Display recent files from viminfo and prompt for editing
#!/bin/bash
#
# Dec 22, 2011
# Display recent files from viminfo and prompt for editing
[ "$vim" ] || vim=vim
[ $viminfo ] || viminfo=~/.viminfo
usage="$(basename $0) [-a] [-l] [-[0-9]] [--debug] [--help] [regexes]"
[ $1 ] || list=1
fnd=()
for x; do case $x in
-a) deleted=1;;
-l) list=1;;
-[1-9]) edit=${x:1}; shift;;
--help) echo $usage; exit;;
--debug) vim=echo;;
--) shift; fnd+=("$@"); break;;
*) fnd+=("$x");;
esac; shift; done
set -- "${fnd[@]}"
[ -f "$1" ] && {
$vim "$1"
exit
}
while IFS=" " read line; do
[ "${line:0:1}" = ">" ] || continue
fl=${line:2}
[ -f "${fl/\~/$HOME/}" -o "$deleted" ] || continue
match=1
for x; do
[[ "$fl" =~ $x ]] || match=
done
[ "$match" ] || continue
i=$((i+1))
files[$i]="$fl"
done < "$viminfo"
if [ "$edit" ]; then
resp=${files[$edit]}
elif [ "$i" = 1 -o "$list" = "" ]; then
resp=${files[1]}
elif [ "$i" ]; then
while [ $i -gt 0 ]; do
echo -e "$i\t${files[$i]}"
i=$((i-1))
done
read -p '> ' CHOICE
resp=${files[$CHOICE]}
fi
[ "$resp" ] || exit
$vim "${resp/\~/$HOME}"
@rkumar
Copy link
Author

rkumar commented Dec 2, 2012

taken from rupa (github)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment