From 914e5f136e5874f74bb32062cb1bb5d66c9b0dde Mon Sep 17 00:00:00 2001 From: rupa Date: Wed, 20 Jul 2016 10:33:05 -0400 Subject: [PATCH] Add -c option: restricts matches to files under $PWD --- README | 4 +++- v | 14 ++++++++++++-- v.1 | 6 +++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/README b/README index 845718b..3c5161f 100644 --- a/README +++ b/README @@ -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 @@ -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 @@ -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 diff --git a/v b/v index 67489e4..502fe10 100755 --- a/v +++ b/v @@ -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;; @@ -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" diff --git a/v.1 b/v.1 index 83162e1..5ae35a5 100644 --- a/v.1 +++ b/v.1 @@ -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 @@ -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 @@ -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