From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15648 invoked by alias); 14 Oct 2015 13:14:15 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 36856 Received: (qmail 22224 invoked from network); 14 Oct 2015 13:14:14 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_HDRS_LCASE, T_MANY_HDRS_LCASE autolearn=ham autolearn_force=no version=3.4.0 X-AuditID: cbfec7f4-f79c56d0000012ee-54-561e52c647ce Date: Wed, 14 Oct 2015 14:04:03 +0100 From: Peter Stephenson To: Zsh Hackers' List Subject: PATCH: minor cdr enhancement Message-id: <20151014140403.26e19993@pwslap01u.europe.root.pri> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrFLMWRmVeSWpSXmKPExsVy+t/xy7rHguTCDL49Erc42PyQyYHRY9XB D0wBjFFcNimpOZllqUX6dglcGYvv/WEuuChRsfJ5QAPjNOEuRk4OCQETiWtPvrJD2GISF+6t Z+ti5OIQEljKKNFzYAYzhDODSaKvYTmUs41R4sORl8wgLSwCqhI3e64wgdhsAoYSUzfNZuxi 5OAQEdCWaP8oBhIWBio59OIUC4jNK2Av8f7HPkYQm19AX+Lq309MEJvtJWZeOcMIUSMo8WPy PbB6ZgEtic3bmlghbHmJzWvegq0VElCXuHF3N/sERoFZSFpmIWmZhaRlASPzKkbR1NLkguKk 9FxDveLE3OLSvHS95PzcTYyQEPyyg3HxMatDjAIcjEo8vBmrZcOEWBPLiitzDzFKcDArifD+ MZALE+JNSaysSi3Kjy8qzUktPsQozcGiJM47d9f7ECGB9MSS1OzU1ILUIpgsEwenVAPjZG/e DQeaHksmn/aY/zBU36lERndvgcLBg0Hdavwn7l1Ztsby3tWpnPKO1i7fOVmyPv/+LJa2jXXt LLOMxp0bna7eUk7t+6EnufUb066CNbvePZ465Rq3xoz/MilfS8SO7e9d0sp69uXpyw//8fBo tTf2PFrWkbVxp2DLVZbSyd+vauj94fUWV2Ipzkg01GIuKk4EAL2AUeo9AgAA 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@samsung.com | Phone: +44 1223 434724 | www.samsung.com