Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: a little problem with the second argument to cd
- X-seq: zsh-users 6611
- From: Dominik Vogt <dominik.vogt@xxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: a little problem with the second argument to cd
- Date: Wed, 24 Sep 2003 17:59:49 +0200
- In-reply-to: <1030924153602.ZM30551@xxxxxxxxxxxxxxxxxxxxxxx>
- Mail-followup-to: zsh-users@xxxxxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20030924135231.GB32061@xxxxxx> <1030924153602.ZM30551@xxxxxxxxxxxxxxxxxxxxxxx>
- Reply-to: zsh-users@xxxxxxxxxx
On Wed, Sep 24, 2003 at 03:36:02PM +0000, Bart Schaefer wrote:
> On Sep 24, 3:52pm, Dominik Vogt wrote:
> } Subject: a little problem with the second argument to cd
> }
> } $ cd foo bar
> } cd: no such file or directory: .../bar/libfoo
> }
> } Can I force zsh to consider foo/libbar as a match too (preferrably
> } without re-implementing the whole functionality as a script)?
>
> The answer is either "no", or "only by manually clarifying", e.g:
>
> $ cd bfoo bbar
>
> The two-arg form of cd does _exactly_ what this does:
>
> cd ${PWD/foo/bar}
>
> There's no "considering" involved, it's a strictly textual replacement
> with no reference to the filesystem.
>
> The function to do what you want would look something like this:
>
> cd2 () {
> integer i=0
> local target="$1"
> if ((ARGC > 1))
> then
> while ((++i)) && [[ "$PWD" != "${(SI-$i-)PWD#${(q)1}}" ]]
> do
> target="${(SI-$i-)PWD/${(q)1}/$2}"
> [[ -d "$target" && -r "$target" ]] && break
> target="${(SI-$i-)PWD//${(q)1}/$2}"
> [[ -d "$target" && -r "$target" ]] && break
> target=
> done
> fi
> cd "${target:-${PWD/${(q)1}/$2}}"
> }
Wow, I love this shell. I thought it would be much more difficult.
Works like a charm, thank you very much!
Ciao
Dominik ^_^ ^_^
Messages sorted by:
Reverse Date,
Date,
Thread,
Author