zsh-users
 help / color / mirror / code / Atom feed
From: Frank Terbeck <ft@bewatermyfriend.org>
To: zsh-users@sunsite.dk
Subject: Re: cd to a file
Date: Sun, 22 Apr 2007 20:18:18 +0200	[thread overview]
Message-ID: <20070422181817.GD16598@fsst.voodoo.lan> (raw)
In-Reply-To: <20070421151225.58926.qmail@smasher.org>

Atom Smasher <atom@smasher.org>:
> 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


  reply	other threads:[~2007-04-22 18:19 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-19 12:43 More zsh tricks required please zzapper
2004-06-19 13:06 ` Christian Schneider
2004-06-20 12:19 ` Julius Plenz
2004-06-21  0:38 ` Drew Perttula
2007-04-16 14:40   ` cd to a file Andy Spiegl
2007-04-16 16:00     ` Frank Terbeck
2007-04-18  1:08       ` Andy Spiegl
2007-04-21 15:12       ` Atom Smasher
2007-04-22 18:18         ` Frank Terbeck [this message]
2007-04-23  8:45           ` Atom Smasher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070422181817.GD16598@fsst.voodoo.lan \
    --to=ft@bewatermyfriend.org \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).