Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: minor cdr enhancement
- X-seq: zsh-workers 36856
- From: Peter Stephenson <p.stephenson@xxxxxxxxxxx>
- To: Zsh Hackers' List <zsh-workers@xxxxxxx>
- Subject: PATCH: minor cdr enhancement
- Date: Wed, 14 Oct 2015 14:04:03 +0100
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- Organization: Samsung Cambridge Solution Centre
diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo
index 635f9b0..d367d8b 100644
--- a/Doc/Zsh/contrib.yo
+++ b/Doc/Zsh/contrib.yo
@@ -415,6 +415,18 @@ newlines, where I have in any case no sympathy); directories are in
unabbreviated from and contain an absolute path, i.e. they start with tt(/).
Usually the first entry should be left as the current directory.
)
+item(tt(-p ')var(pattern)tt('))(
+Prunes any items in the directory list that match the given extended glob
+pattern; the pattern needs to be quoted from immediate expansion on the
+command line. The pattern is matched against each completely expanded
+file name in the list; the full string must match, so wildcards at the
+end (e.g. tt('*removeme*')) are needed to remove entries with a given
+substring.
+
+If output is to a terminal, then the function will print the new list
+after pruning and prompt for confirmation by the user. This output and
+confirmation step can be skipped by using tt(-P) instead of tt(-p).
+)
enditem()
subsect(Configuration)
diff --git a/Functions/Chpwd/cdr b/Functions/Chpwd/cdr
index 4f39910..4bed88b 100644
--- a/Functions/Chpwd/cdr
+++ b/Functions/Chpwd/cdr
@@ -51,6 +51,13 @@
# (and only /). Usually the first entry should be left as the current
# directory.
#
+# "cdr -p 'pattern'" prunes anything matching the given extended glob
+# pattern from the directory list. The match is against the fully
+# expanded directory path and the full string must match (use wildcards
+# at the ends if needed). If output is going to a terminal, the
+# function will print the new list for the user to confrim; this can be
+# skipped by giving -P instead of -p.
+#
# Details of directory handling
# =============================
#
@@ -217,11 +224,11 @@ setopt extendedglob
autoload -Uz chpwd_recent_filehandler chpwd_recent_add
-integer list set_reply i bad edit
-local opt dir
+integer list set_reply i bad edit force_prune
+local opt dir prune
local -aU dirs
-while getopts "elr" opt; do
+while getopts "elp:P:r" opt; do
case $opt in
(e)
edit=1
@@ -231,6 +238,12 @@ while getopts "elr" opt; do
list=1
;;
+ ([pP])
+ prune=$OPTARG
+ edit=1
+ [[ $opt = P ]] && force_prune=1
+ ;;
+
(r)
set_reply=1
;;
@@ -278,10 +291,22 @@ if [[ $PWD != $reply[1] ]]; then
fi
if (( edit )); then
- local compcontext='directories:directory:_path_files -/'
-IFS='
+ if [[ -n $prune ]]; then
+ reply=(${reply:#$~prune})
+ if [[ force_prune -eq 0 && -t 1 ]]; then
+ print -nrl "New list:" $reply 'Accept? '
+ if ! read -q; then
+ print
+ return 1
+ fi
+ print
+ fi
+ else
+ local compcontext='directories:directory:_path_files -/'
+ IFS='
' vared reply || return 1
-chpwd_recent_filehandler $reply
+ fi
+ chpwd_recent_filehandler $reply
fi
# Skip current directory if present (may have been pruned).
--
Peter Stephenson | Principal Engineer Samsung Cambridge Solution Centre
Email: p.stephenson@xxxxxxxxxxx | Phone: +44 1223 434724 |
www.samsung.com
Messages sorted by:
Reverse Date,
Date,
Thread,
Author