From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7638 invoked by alias); 21 May 2012 17:55:55 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 17097 Received: (qmail 11706 invoked from network); 21 May 2012 17:55: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=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <120521105448.ZM32691@torch.brasslantern.com> Date: Mon, 21 May 2012 10:54:48 -0700 In-reply-to: <1337346499.24458.140661077281237.140CF9BF@webmail.messagingengine.com> Comments: In reply to Ronald Fischer "Re: global aliases substituting *within* a path" (May 18, 3:08pm) References: <1337346499.24458.140661077281237.140CF9BF@webmail.messagingengine.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: global aliases substituting *within* a path MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On May 18, 3:08pm, Ronald Fischer wrote: } } > echo a/f/b/b/x } } Doesn't help here, for two reason: } } (1) At least in my version of zsh (4.3.12), this would not expand the } interim directories (f,b,b). Does your zsh configuration include installing the completion system (the "compinit" command)? } (2) Even if I could do TAB completion on directories within the path, } this is not what I'm looking for, because it is still cumbersome to } type. You might want to look at named directories: hash -d aaa=aaa/foo/bar/baz hash -d bbb=bbb/foo/bar/baz hash -d ccc=ccc/foo/bar/baz Then you can write ls ~aaa/xxx ls ~bbb/yyy ls ~ccc/zzz I don't know how much variation there is in the "foo/bar/baz" part of your structure. You can try using dynamic named directories: X=foo/bar/baz ls ~[aaa/X]/xxx That's not saving any keystrokes over aaa/$X/xxx but might have some aesthetic advantages. It's implemented with something like this: stem_name_hook() { case $1 in (n) local root=$2:h stem=$2:t reply=( $root/${(P)stem} ) ;; (*) return 1; esac } autoload -Uz add-zsh-hook add-zsh-hook zsh_directory_name stem_name_hook The above allows ANY leading path (the "root") and ANY variable name (the "stem") after the slash to be the "middle of the path", e.g. Y=fare/thee/well ls ~[/usr/local/Y]/yyy You could of course apply a similar transformation on the root instead (or as well) but that's not much different than ordinary "hash -d" with perhaps auto_name_dirs enabled. If you want to be able to use it in completions and other automatic path contractions, you need a reverse mapping that provides a sensible set of root and stem names. Here's one that uses ONLY aaa, bbb, ccc for roots and ONLY $X for the stem: stem_name_hook() { case $1 in (n) reply=( $2:h/$X ) ;; (d) reply=( ${2/\/$X(\/*|)/\/X}) reply=($reply ${#reply[1]} ) ;; (c) local dirs dirs=( (aaa|bbb|ccc)/$X ) if (( $#dirs )); then dirs=( ${^dirs%$X}X ) _wanted dynamic-dirs expl 'dynamic directory' \ compadd -S \] -a dirs else return 1 fi ;; (*) return 1; esac } I'm not entirely sure about that (c) branch, which is for compsys [cf. my response to (1)]. PWS is the expert on dynamic directory hooks. -- Barton E. Schaefer