From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2328 invoked from network); 22 Apr 2007 18:19:32 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.8 (2007-02-13) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,FORGED_RCVD_HELO autolearn=ham version=3.1.8 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 22 Apr 2007 18:19:32 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 7530 invoked from network); 22 Apr 2007 18:19:26 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 22 Apr 2007 18:19:26 -0000 Received: (qmail 20180 invoked by alias); 22 Apr 2007 18:19:18 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 11442 Received: (qmail 20170 invoked from network); 22 Apr 2007 18:19:18 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 22 Apr 2007 18:19:18 -0000 Received: (qmail 6169 invoked from network); 22 Apr 2007 18:19:18 -0000 Received: from mta-1.ms.rz.rwth-aachen.de (134.130.7.72) by a.mx.sunsite.dk with SMTP; 22 Apr 2007 18:19:14 -0000 Received: from r220-1 ([134.130.3.31]) by mta-1.ms.rz.RWTH-Aachen.de (Sun Java System Messaging Server 6.2-7.05 (built Sep 5 2006)) with ESMTP id <0JGW00HBSW82C5B0@mta-1.ms.rz.RWTH-Aachen.de> for zsh-users@sunsite.dk; Sun, 22 Apr 2007 20:19:14 +0200 (CEST) Received: from relay.rwth-aachen.de ([134.130.3.1]) by r220-1 (MailMonitor for SMTP v1.2.2 ) ; Sun, 22 Apr 2007 20:19:13 +0200 (MEST) Received: from fsst.voodoo.lan ([212.117.84.93]) by relay.rwth-aachen.de (8.13.7/8.13.3/1) with ESMTP id l3MIJC9W016613 for ; Sun, 22 Apr 2007 20:19:12 +0200 (MEST) Received: from hawk by fsst.voodoo.lan with local (Exim 4.63) (envelope-from ) id 1Hfgde-0008A8-58 for zsh-users@sunsite.dk; Sun, 22 Apr 2007 20:18:18 +0200 Date: Sun, 22 Apr 2007 20:18:18 +0200 From: Frank Terbeck Subject: Re: cd to a file In-reply-to: <20070421151225.58926.qmail@smasher.org> To: zsh-users@sunsite.dk Mail-followup-to: zsh-users@sunsite.dk Message-id: <20070422181817.GD16598@fsst.voodoo.lan> MIME-version: 1.0 Content-type: text/plain; charset=iso-8859-1 Content-transfer-encoding: 7BIT Content-disposition: inline References: <20070416160051.GB28724@fsst.voodoo.lan> <20070421151225.58926.qmail@smasher.org> User-Agent: Mutt/1.5.15+20070412 (2007-04-11) Atom Smasher : > not nearly as elaborate as Frank Terbeck's function, but i think this > provides the basic functionality to cd to a file without breaking > anything. the "echo" command is very much optional... Hm, I actually think, that my wrapper works for most (all?) possible invocations of the 'cd' builtin. > cd() { > ## cd to a file > if [ 1 = "${#}" ] && [ '-' != "${1}" ] && [ \! -d "${1}" ] && [ -d "${1:h}" ] > then > echo "correcting \"${1}\" to \"${1:h}\"" >&2 > builtin cd "${1:h}" > else > builtin cd "${@}" > fi > } This breaks things like 'cd -2', 'cd +2' or 'cd +'. Regards, Frank -- In protocol design, perfection has been reached not when there is nothing left to add, but when there is nothing left to take away. -- RFC 1925