From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 496 invoked by alias); 11 Jan 2016 11:58:13 -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: 21147 Received: (qmail 16800 invoked from network); 11 Jan 2016 11:58:12 -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 autolearn=ham autolearn_force=no version=3.4.0 X-AuditID: cbfec7f4-f79026d00000418a-b1-569398cf1083 Date: Mon, 11 Jan 2016 11:58:04 +0000 From: Peter Stephenson To: Zsh Users Subject: Re: cd "" foo bug? Message-id: <20160111115804.00a8661b@pwslap01u.europe.root.pri> In-reply-to: <20160111112026.GA14816@linux.vnet.ibm.com> References: <20160111112026.GA14816@linux.vnet.ibm.com> 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+NgFjrPLMWRmVeSWpSXmKPExsVy+t/xK7rnZ0wOMzhyRNBix8mVjA6MHqsO fmAKYIzisklJzcksSy3St0vgyng08xZbwTvOitPbG5gbGNewdzFyckgImEhs3r2GFcIWk7hw bz0biC0ksJRR4utthS5GLiB7GpPEgff3WSCcc4wSvdc3M0E4ZxkldjRtYOxi5OBgEVCV+H7O FKSbTcBQYuqm2YwgtoiAosSZX9+YQGxhAWmJi8t+soDYvAL2Ehu+vQO7glPAQmL1ll+MEJvN JR58eQhm8wvoS1z9+4kJ4jp7iZlXzjBC9ApK/Jh8D2wOs4CWxOZtTawQtrzE5jVvmSHmqEvc uLubfQKj8CwkLbOQtMxC0rKAkXkVo2hqaXJBcVJ6rqFecWJucWleul5yfu4mRkgwf9nBuPiY 1SFGAQ5GJR5ehx2TwoRYE8uKK3MPMUpwMCuJ8O7OnhwmxJuSWFmVWpQfX1Sak1p8iFGag0VJ nHfurvchQgLpiSWp2ampBalFMFkmDk6pBkbDgt1h/+8y3uH7e5l337ofj7IubDnYvea53lHJ TJ1T85577DIWKqhdsKev/8aWFRz1T5RXKXUvNfhznW+P81yuXYF/wqJ0Xtmw8k6O6Hzr/u7C Jaa4P+8FPvDs0ZEV7XpatCAzWaL78bY5V6y/lDj8Kax85/Jc3Ffz3PsW6+f9x/odVrpaBZ5U YinOSDTUYi4qTgQA9bNen2ICAAA= On Mon, 11 Jan 2016 12:20:26 +0100 Dominik Vogt wrote: > cd with two arguments works fine if the second argument is an > empty string, but not if the first argument is an empty string. > Shouldn't it try all possible positions for the "" instead of just > the first one? That's not really compatible with how two-argument cd normally works. % mkdir ~/tmp/foofoo ~/tmp/foobar % cdpath=(~/tmp) % cd ~/tmp/foofoo % cd foo bar cd: no such file or directory: /export/home/pws/tmp/barfoo If it's going to try all possible source matches it should do it in this case, too. As it is, it always just tries the first match. This sounds more like an extension for a function. The (I) flag already handles the special case of an empty string the way you want, so no special cases within the function. pws # should handle options up here... if (( $# == 2 )); then local src=$1 rep=$2 dir integer n=1 while true; do dir=${(I:${n}:)PWD/$src/$rep} if [[ $dir = $PWD ]]; then print -r "$0: no replacements found: $PWD / \"$src\" / \"$rep\"" >&2 return 1 fi if [[ -d $dir ]]; then cd -- $dir return fi (( n++ )) done else builtin cd "$@" fi