-
-
Save rkumar/4188977 to your computer and use it in GitHub Desktop.
# Display recent files from viminfo and prompt for editing
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
#!/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}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
taken from rupa (github)