From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8919 invoked from network); 16 Apr 2007 14:41:28 -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; 16 Apr 2007 14:41:28 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 76305 invoked from network); 16 Apr 2007 14:41:16 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 16 Apr 2007 14:41:16 -0000 Received: (qmail 7138 invoked by alias); 16 Apr 2007 14:40:54 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 11404 Received: (qmail 7128 invoked from network); 16 Apr 2007 14:40:52 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 16 Apr 2007 14:40:52 -0000 Received: (qmail 74602 invoked from network); 16 Apr 2007 14:40:52 -0000 Received: from sienna.akte.de (HELO ds80-237-184-21.dedicated.hosteurope.de) (80.237.184.21) by a.mx.sunsite.dk with SMTP; 16 Apr 2007 14:40:49 -0000 Received: (root@ds80-237-184-21.dedicated.hosteurope.de) by sienna.akte.de id ; Mon, 16 Apr 2007 16:40:29 +0200 KRecCount: 1 X-Originating-IP: [87.152.143.95] X-KInfo: virscan ok X-KInfo: !spam auth Received: from condor.int.spiegl.de (p57988F5F.dip.t-dialin.net [87.152.143.95]) by sienna.akte.de via kasmail (3.1) id <1IdSNM-1Ty-1-sienna>; Mon, 16 Apr 2007 14:40:19 GMT Received: from condor.int.spiegl.de (spiegl@localhost [127.0.0.1]) by condor.int.spiegl.de (8.13.8/8.13.8/Debian-3) with ESMTP id l3GEeG8S021195 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Mon, 16 Apr 2007 16:40:16 +0200 Received: (from spiegl@localhost) by condor.int.spiegl.de (8.13.8/8.13.8/Submit) id l3GEeGZJ021190 for zsh-users@sunsite.dk; Mon, 16 Apr 2007 16:40:16 +0200 X-Authentication-Warning: condor.int.spiegl.de: spiegl set sender to zsh.Andy@spiegl.de using -f Date: Mon, 16 Apr 2007 16:40:16 +0200 From: Andy Spiegl To: zsh-users@sunsite.dk Subject: cd to a file Message-ID: <20070416144016.GA20630@spiegl.de> Mail-Followup-To: zsh-users@sunsite.dk References: <200406210039.i5L0dsrq022663@bang.bigasterisk.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200406210039.i5L0dsrq022663@bang.bigasterisk.com> X-PGP-GPG-Keys: mail -s "send pgp" auto@spiegl.de X-Fingerprint: Key-ID C2CB30F0: 9051 50B9 13B0 57B9 10FD 48AC 4FA1 209B C2CB 30F0 X-Accepted-File-Formats: ASCII OpenOffice .rtf .pdf - *NO* Microsoft files please. X-why-you-shouldnt-use-MS-LookOut: http://www.jensbenecke.de/l-oe-en.php X-warum-man-MS-Outlook-vermeiden-sollte: http://www.jensbenecke.de/l-oe-de.php X-how-to-quote: http://www.afaik.de/usenet/faq/zitieren/ X-how-to-ask-questions: http://www.catb.org/~esr/faqs/smart-questions.html X-stupid-disclaimers: http://goldmark.org/jeff/stupid-disclaimers/ User-Agent: Mutt/1.5.9i Hi, a long while ago Drew Perttula posted this very useful function: > # cd to a file should take you to the dir that contains the file > # courtesy of Artur Penttinen > function cd () { > if [[ -f $1 ]]; then > builtin cd $1:h > else > builtin cd $1 > fi > } I just noticed that it breaks cd substitution (cd with 2 arguments) and patched it like this: # cd to a file should take you to the dir that contains the file # courtesy of Artur Penttinen function cd () { if [[ -n $2 ]]; then builtin cd $1 $2 elif [[ -f $1 ]]; then builtin cd $1:h else builtin cd $* fi } Could still be optimized though, I guess. Andy. -- Fotos: familie.spiegl.de Info: peru.spiegl.de Weblog: blog.spiegl.de Mail: andy@spiegl.de -- Finagle's Second Law: No matter what the anticipated result, there will always be someone eager to (a) misinterpret it, (b) fake it, or (c) believe it happened according to his own pet theory.