Skip to content

Commit 914e5f1

Browse files
author
rupa
committed
Add -c option: restricts matches to files under $PWD
1 parent 252b9f1 commit 914e5f1

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

README

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ NAME
77

88

99
SYNOPSIS
10-
v [-a] [-l] [-[0-9]] [--debug] [--help] [regex1 regex2 ... regexn]
10+
v [-a] [-c] [-l] [-[0-9]] [--debug] [--help] [regex1 regex2 ... regexn]
1111

1212

1313
AVAILABILITY
@@ -30,6 +30,7 @@ DESCRIPTION
3030

3131
OPTIONS
3232
-a don't skip deleted files
33+
-c restrict matches to subdirectories of the current dir
3334
-l when multiple matches, show a list
3435
-[0-9] edit nth most recent file
3536
--debug dry run
@@ -40,6 +41,7 @@ EXAMPLES
4041
v list and choose from all files
4142
v -0 reopen most recently edited file
4243
v foo bar edit first file matching foo and bar
44+
v -c foo bar choose files in current dir matching foo and bar
4345
v -l foo bar list and choose files matching foo and bar
4446

4547

v

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
[ "$vim" ] || vim=vim
44
[ $viminfo ] || viminfo=~/.viminfo
55

6-
usage="$(basename $0) [-a] [-l] [-[0-9]] [--debug] [--help] [regexes]"
6+
usage="$(basename $0) [-a] [-c] [-l] [-[0-9]] [--debug] [--help] [regexes]"
77

88
[ $1 ] || list=1
99

10+
_pwd="$(command pwd)"
11+
1012
fnd=()
1113
for x; do case $x in
1214
-a) deleted=1;;
15+
-c) subdir=1; shift;;
1316
-l) list=1;;
1417
-[0-9]) edit=${x:1}; shift;;
1518
--help) echo $usage; exit;;
@@ -27,11 +30,18 @@ set -- "${fnd[@]}"
2730
while IFS=" " read line; do
2831
[ "${line:0:1}" = ">" ] || continue
2932
fl=${line:2}
30-
[ -f "${fl/\~/$HOME/}" -o "$deleted" ] || continue
33+
_fl="${fl/~\//$HOME/}"
34+
[ -f "$_fl" -o "$deleted" ] || continue
3135
match=1
3236
for x; do
3337
[[ "$fl" =~ $x ]] || match=
3438
done
39+
[ "$subdir" ] && {
40+
case "$_fl" in
41+
$_pwd*);;
42+
*) match=;;
43+
esac
44+
}
3545
[ "$match" ] || continue
3646
i=$((i+1))
3747
files[$i]="$fl"

v.1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
v \- z for vim
55

66
.SH SYNOPSIS
7-
v [\-a] [\-l] [\-[0\-9]] [\-\-debug] [\-\-help] [regex1 regex2 ... regexn]
7+
v [\-a] [\-c] [\-l] [\-[0\-9]] [\-\-debug] [\-\-help] [regex1 regex2 ... regexn]
88

99
.SH AVAILABILITY
1010
bash, vim
@@ -25,6 +25,8 @@ provided regular expressions.
2525
.SH OPTIONS
2626
\fB\-a\fR don't skip deleted files
2727
.br
28+
\fB\-c\fR restrict matches to subdirectories of the current dir
29+
.br
2830
\fB\-l\fR when multiple matches, show a list
2931
.br
3032
\fB\-[0\-9]\fR edit nth most recent file
@@ -40,6 +42,8 @@ provided regular expressions.
4042
.br
4143
\fBv foo bar\fR edit first file matching foo and bar
4244
.br
45+
\fBv -c foo bar\fR choose files in current dir matching foo and bar
46+
.br
4347
\fBv -l foo bar\fR list and choose files matching foo and bar
4448

4549
.SH NOTES

0 commit comments

Comments
 (0)