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 6610
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: a little problem with the second argument to cd
- Date: Wed, 24 Sep 2003 15:36:02 +0000
- In-reply-to: <20030924135231.GB32061@xxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20030924135231.GB32061@xxxxxx>
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}}"
}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author