Skip to content

Commit

Permalink
Add -c option: restricts matches to files under $PWD
Browse files Browse the repository at this point in the history
  • Loading branch information
rupa committed Jul 20, 2016
1 parent 252b9f1 commit 914e5f1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ NAME


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


AVAILABILITY
Expand All @@ -30,6 +30,7 @@ DESCRIPTION

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


Expand Down
14 changes: 12 additions & 2 deletions v
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
[ "$vim" ] || vim=vim
[ $viminfo ] || viminfo=~/.viminfo

usage="$(basename $0) [-a] [-l] [-[0-9]] [--debug] [--help] [regexes]"
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;;
Expand All @@ -27,11 +30,18 @@ set -- "${fnd[@]}"
while IFS=" " read line; do
[ "${line:0:1}" = ">" ] || continue
fl=${line:2}
[ -f "${fl/\~/$HOME/}" -o "$deleted" ] || continue
_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"
Expand Down
6 changes: 5 additions & 1 deletion v.1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
v \- z for vim

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

.SH AVAILABILITY
bash, vim
Expand All @@ -25,6 +25,8 @@ provided regular expressions.
.SH OPTIONS
\fB\-a\fR don't skip deleted files
.br
\fB\-c\fR restrict matches to subdirectories of the current dir
.br
\fB\-l\fR when multiple matches, show a list
.br
\fB\-[0\-9]\fR edit nth most recent file
Expand All @@ -40,6 +42,8 @@ provided regular expressions.
.br
\fBv foo bar\fR edit first file matching foo and bar
.br
\fBv -c foo bar\fR choose files in current dir matching foo and bar
.br
\fBv -l foo bar\fR list and choose files matching foo and bar

.SH NOTES
Expand Down

0 comments on commit 914e5f1

Please sign in to comment.