From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22269 invoked by alias); 28 Feb 2014 13:41:11 -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: 32441 Received: (qmail 24545 invoked from network); 28 Feb 2014 13:40:54 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s1024; t=1393594449; bh=lcxdnJ79XOzdvUIV3V5sFDYpPRgbsHSdrehWzlzW5cw=; h=X-Yahoo-Newman-Id:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:X-Rocket-Received:Received:From:To:Subject:MIME-Version:Content-Type:Content-ID:Date:Message-ID; b=jRbbsWgAtPMLfQ9tEU4qynoTSYe7JlO78NaA0ogD4i8mtG3VtaIMvSLb+Sx4AaegoboTcivda5LtSNMRVRqhK/WgwWwnC37NPR7/BoziILQJ7C68bI2Xmc2hsAeQfs1Ayu5xixyr0QLnxrDUtbk7JFxXBC54pr/SIz8eHlzJrrw= X-Yahoo-Newman-Id: 899635.92326.bm@smtp127.mail.ir2.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: F9XhLAkVM1mMwwy.EHcuM0bnI_CagyHouxeMbiVZTsFYU3N N4p.uQ9ncYqp07p_1FbxiouS_dG6HKauvpNU.46YaxHEOmTJTyEucKv3TjxZ d3y6wqc0s6KETcJunnrEukraFruv4loa0hzZ_01eyc7hrbAM9EF0GlweD_8K G8Pj3G2UxxFjmgyMp5IxnbwzmKeZ3f1rIBKPaGNhtMrQpblgsTVLvMIPS7we QJJlB5Hl__PrYg1lqtPY1tNVWg4pXYyiN.zpx6fks6z_WcPWUoX_AO9KYLMi tp8aHdtVRMnxbTJ13X_QO191MOpCHbhSmzXaFTxe_46Gzud_Tblwt1FWySVy irfG8T5bukmAmmiEmnLgpa8SgjSojaVZgvKOTzuexug5Y5ZKBR81RENwB058 Q9WletXTCvJap9m3LeutRj0wF0EunUowtrPkFNBziB6z5Vn151Aucxvo5zwu CMX8XQY_GVxp3.5J6G3b_wK_ZeXbusAjjVYlWhE6ISw_zWFmWMTdOp5aV4k5 HN7y.4NzQRFkvahiIMVu.Sapfng-- X-Yahoo-SMTP: opAkk_CswBAce_kJ3nIPlH80cJI- X-Rocket-Received: from kiddle.eu (okiddle@5.146.59.147 with plain [188.125.69.59]) by smtp127.mail.ir2.yahoo.com with SMTP; 28 Feb 2014 13:34:09 +0000 UTC From: Oliver Kiddle To: Zsh workers Subject: completer for file extensions MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <29010.1393594448.1@thecus.kiddle.eu> Date: Fri, 28 Feb 2014 14:34:08 +0100 Message-ID: <29011.1393594448@thecus.kiddle.eu> This is a completer for filename extensions after *. (or ^*.). So, for example, you might have: % rm *. .patch .pdf.gz .tar.gz .html .gz File extensions are usually short so this probably doesn't seem particularly useful but it doesn't really interfere with anything else and it is actually sometimes useful. I think I originally wrote this with the idea of it being a simple example for the bash2zsh book but it didn't get used there and in the form below, it isn't quite as simple as it was. Directories before *. are handled, so /tmp/*. will complete extensions of files in /tmp but something like a*. is not: wouldn't be hard but I'm not sure it'd be useful. In the past I've always used this after _expand but I've attempted to make it better handle exact matches so it can be used before _expand or _match. Unfortunately, with compadd -O, you can't tell if any of the matches were exact. Oliver diff --git a/Completion/Base/Completer/_extensions b/Completion/Base/Completer/_extensions new file mode 100644 index 0000000..2fcfe82 --- /dev/null +++ b/Completion/Base/Completer/_extensions @@ -0,0 +1,32 @@ +#autoload + +# This completer completes filename extensions when completing +# after *. or ^*. It can be used anywhere in the completer list +# but if used after _expand, patterns that already match a file +# will be expanded before it is called. + +compset -P '(#b)([~$][^/]#/|)(*/|)(\^|)\*.' || return 1 + +local -aU files +local -a expl suf mfiles + +files=( ${(e)~match[1]}${match[2]}*.* ) || return 1 +eval set -A files '${(MSI:'{1-${#${(O)files//[^.]/}[1]}}':)files%%.[^/]##}' + +if zstyle -t ":completion:${curcontext}:extensions" prefix-hidden; then + files=( ${files#.} ) +else + PREFIX=".$PREFIX" + IPREFIX="${IPREFIX%.}" +fi + +zstyle -T ":completion:${curcontext}:extensions" add-space || + suf=( -S '' ) + +_description extensions expl 'file extension' + +# for an exact match, fail so as to give _expand or _match a chance. +compadd -O mfiles "$expl[@]" -a files +[[ $#mfiles -gt 1 || ${mfiles[1]} != $PREFIX ]] && + compadd "$expl[@]" "$suf[@]" -a files && + [[ -z $compstate[exact_string] ]] diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index c304461..603a5ad 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -3038,6 +3038,15 @@ This function is also a bindable command, see ifzman(the section `Bindable Commands' below)\ ifnzman(noderef(Bindable Commands)). ) +findex(_extensions) +item(tt(_extensions))( +If the cursor follows the string `tt(*.)', filename extensions are +completed. The extensions are taken from files in current directory or a +directory specified at the beginning of the current word. For exact matches, +completion continues to allow other completers such as tt(_expand) to +expand the pattern. The standard tt(add-space) and tt(prefix-hidden) +styles are observed. +) findex(_history) item(tt(_history))( Complete words from the shell's command history. This completer