From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16439 invoked by alias); 11 Mar 2011 01:06:52 -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: 15858 Received: (qmail 22244 invoked from network); 11 Mar 2011 01:06:51 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) 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.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 209.85.220.171 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:date:message-id:subject:from:to :content-type; bh=c5XQRQ0uV3w8Ngs9OHqCyrh5EZbxurO+8xCoCwMA/mI=; b=CnWtMUvrccXSfKricHN6SGf41+cDlA+adOhw2EM6NpdzBqS7nwUlTCzOpI2kOc9AN/ JT0fK5a7A+pS5s43U/VfyxGir0sJGESdxpUD2YHVzuaLZfBuT/sSa96W9QHAsmvyhMpD xlvsNul5QtqsYAinLCRoIuw5wYDKi9PYiq7CI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=advi9aFawU+BLpB7K0Z3zluSzw4io8fgZOhSZtHGxXxAo2zoAA3brK+SI414C7LT7U AG8tOFYk+NkLUBRd66F1LfdIQYtKaNg5Uj/t4EtpoT7qjUFNVrqb10Nn8b5SbXWt0v56 BNEgiA0mbl5fY113TEBitqXjyNAtykUUmzKYw= MIME-Version: 1.0 Date: Fri, 11 Mar 2011 02:06:45 +0100 Message-ID: Subject: possibly useful zsh_directory_name implementation From: Mikael Magnusson To: Zsh Users Content-Type: text/plain; charset=UTF-8 function zsh_directory_name () { case $1 in n) case $2 in /*) reply=( /${(j:/:)${(s:/:)PWD}[1,(er)${2[2,-1]}]} ) ;; .*) reply=( (../)##${2[2,-1]}([1]) ) ;; esac ;; c) local types vals description types=( '.:children of parent directories' '/:pwd segment' ) case $PREFIX in '') vals=( $types ) _describe 'dynamic dir type' vals -V dynamic-dirs -o -S '' ;; .*) vals=( (../)##*~(../)##$PWD:t(/:t) ) ;| /*) vals=( "${(@)${(s:/:)PWD}[1,-2]}" ) ;| *) _wanted -V dynamic-dirs expl ${${types[(r)$PREFIX[1]*]}[3,-1]} compadd -P $PREFIX[1] -qQS / -d vals ${(q)^vals}\] esac ;; esac } With this, /home/mikachu/some/directory/somewhere% cd ~[/some], will take you to /home/mikachu/some/, and cd ~[.foo] will take you to foo/ in whatever parent directory has a subdirectory foo, for example it could be /home/foo/. -- Mikael Magnusson footnotes: reply=( $PWD[1,(r)$2] ) of course is the more obvious solution, but it doesn't work on directories called "[foo] something". the fiddling with (q)^\] and -Q is because i want only / to be a removable suffix, not the ].