-
Notifications
You must be signed in to change notification settings - Fork 37
/
v
executable file
·65 lines (56 loc) · 1.33 KB
/
v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env bash
# Copyright (c) 2011 rupa deadwyler. Licensed under the WTFPL license, Version 2
[ "$vim" ] || vim=vim
[ $viminfo ] || viminfo=~/.viminfo
usage="$(basename $0) [-a] [-c] [-l] [-[0-9]] [--debug] [--help] [regexes]"
[ $1 ] || list=1
_pwd="$(command pwd)"
fnd=()
for x; do case $x in
-a) deleted=1;;
-c) subdir=1; shift;;
-l) list=1;;
-[0-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}
_fl="${fl/~\//$HOME/}"
[ -f "$_fl" -o "$deleted" ] || continue
match=1
for x; do
[[ "$fl" =~ $x ]] || match=
done
[ "$subdir" ] && {
case "$_fl" in
$_pwd*);;
*) match=;;
esac
}
[ "$match" ] || continue
i=$((i+1))
files[$i]="$fl"
done < "$viminfo"
if [ "$edit" ]; then
resp=${files[$((edit+1))]}
elif [ "$i" = 1 -o "$list" = "" ]; then
resp=${files[1]}
elif [ "$i" ]; then
while [ $i -gt 0 ]; do
echo -e "$((i-1))\t${files[$i]}"
i=$((i-1))
done
read -p '> ' CHOICE
[ "$CHOICE" ] && resp=${files[$((CHOICE+1))]}
fi
[ "$resp" ] || exit
$vim "${resp/\~/$HOME}"