From f186800c130064f6ef4b3d3207337eedb8694933 Mon Sep 17 00:00:00 2001 From: rupa Date: Mon, 25 Feb 2013 01:42:05 -0500 Subject: [PATCH 1/5] Add Makefile for README --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..dcf433d --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +readme: + @groff -man -Tascii z.1 | col -bx + +.PHONY: readme From b554f713992edf10d063c1d7b0a7d2239e958719 Mon Sep 17 00:00:00 2001 From: rupa Date: Sun, 3 Mar 2013 00:51:32 -0500 Subject: [PATCH 2/5] Use _Z_CMD in z -h --- z.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/z.sh b/z.sh index 1aebd2a..b441a5a 100755 --- a/z.sh +++ b/z.sh @@ -100,7 +100,7 @@ _z() { else # list/go while [ "$1" ]; do case "$1" in - -h) echo "z [-h][-l][-r][-t] args" >&2; return;; + -h) echo "${_Z_CMD:-z} [-h][-l][-r][-t] args" >&2; return;; -l) local list=1;; -r) local typ="rank";; -t) local typ="recent";; From 0f3f7a437f8d79c2c822f3d24377449bded127c7 Mon Sep 17 00:00:00 2001 From: rupa Date: Sun, 3 Mar 2013 00:54:40 -0500 Subject: [PATCH 3/5] -c option restricts matches to subdirs of cwd. Closes #83 --- README | 4 +++- z.1 | 5 ++++- z.sh | 6 ++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README b/README index 77c0d40..40e7af4 100644 --- a/README +++ b/README @@ -6,7 +6,7 @@ NAME z - jump around SYNOPSIS - z [-h] [-l] [-r] [-t] [regex1 regex2 ... regexn] + z [-c] [-h] [-l] [-r] [-t] [regex1 regex2 ... regexn] AVAILABILITY bash, zsh @@ -18,6 +18,8 @@ DESCRIPTION directory that matches ALL of the regexes given on the command line. OPTIONS + -c restrict matches to subdirectories of the current directory. + -h show a brief help message -l list only diff --git a/z.1 b/z.1 index 9752ab1..bed5d3b 100644 --- a/z.1 +++ b/z.1 @@ -4,7 +4,7 @@ NAME z \- jump around .SH SYNOPSIS -z [\-h] [\-l] [\-r] [\-t] [regex1 regex2 ... regexn] +z [\-c] [\-h] [\-l] [\-r] [\-t] [regex1 regex2 ... regexn] .SH AVAILABILITY bash, zsh @@ -17,6 +17,9 @@ directory that matches ALL of the regexes given on the command line. .SH OPTIONS .TP +\fB\-c\fR +restrict matches to subdirectories of the current directory. +.TP \fB\-h\fR show a brief help message .TP diff --git a/z.sh b/z.sh index b441a5a..aec8967 100755 --- a/z.sh +++ b/z.sh @@ -19,7 +19,8 @@ # * z foo bar # cd to most frecent dir matching foo and bar # * z -r foo # cd to highest ranked dir matching foo # * z -t foo # cd to most recently accessed dir matching foo -# * z -l foo # list all dirs matching foo (by frecency) +# * z -l foo # list matches instead of cd +# * z -c foo # restrict matches to subdirs of $PWD case $- in *i*) ;; @@ -100,7 +101,8 @@ _z() { else # list/go while [ "$1" ]; do case "$1" in - -h) echo "${_Z_CMD:-z} [-h][-l][-r][-t] args" >&2; return;; + -c) local fnd="$PWD $fnd";; + -h) echo "${_Z_CMD:-z} [-c][-h][-l][-r][-t] args" >&2; return;; -l) local list=1;; -r) local typ="rank";; -t) local typ="recent";; From ce3330e91f22cfcbc421c02767119e36f24ad638 Mon Sep 17 00:00:00 2001 From: rupa Date: Sun, 3 Mar 2013 01:59:26 -0500 Subject: [PATCH 4/5] Make -c without args work like regular z does --- z.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/z.sh b/z.sh index aec8967..a551d24 100755 --- a/z.sh +++ b/z.sh @@ -109,7 +109,7 @@ _z() { --) while [ "$1" ]; do shift; local fnd="$fnd $1";done;; *) local fnd="$fnd $1";; esac; local last=$1; shift; done - [ "$fnd" ] || local list=1 + [ "$fnd" -a "$fnd" != "$PWD " ] || local list=1 # if we hit enter on a completion just go there case "$last" in From f5e4ff6a26d7c2efc51cfc1447c7478c3e75d33c Mon Sep 17 00:00:00 2001 From: rupa Date: Sun, 24 Feb 2013 16:19:16 -0500 Subject: [PATCH 5/5] test directly, instead of testing exit variable --- z.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/z.sh b/z.sh index a551d24..7b0f02e 100755 --- a/z.sh +++ b/z.sh @@ -215,7 +215,8 @@ elif complete &> /dev/null; then complete -o filenames -C '_z --complete "$COMP_LINE"' ${_Z_CMD:-z} [ "$_Z_NO_PROMPT_COMMAND" ] || { # bash populate directory list. avoid clobbering other PROMPT_COMMANDs. - echo $PROMPT_COMMAND | grep -q "_z --add" - [ $? -gt 0 ] && PROMPT_COMMAND='_z --add "$(pwd '$_Z_RESOLVE_SYMLINKS' 2>/dev/null)" 2>/dev/null;'"$PROMPT_COMMAND" + echo $PROMPT_COMMAND | grep -q "_z --add" || { + PROMPT_COMMAND='_z --add "$(pwd '$_Z_RESOLVE_SYMLINKS' 2>/dev/null)" 2>/dev/null;'"$PROMPT_COMMAND" + } } fi