Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: cd "" foo bug?
On Mon, 11 Jan 2016 12:20:26 +0100
Dominik Vogt <vogt@xxxxxxxxxxxxxxxxxx> wrote:
> cd with two arguments works fine if the second argument is an
> empty string, but not if the first argument is an empty string.
> Shouldn't it try all possible positions for the "" instead of just
> the first one?
That's not really compatible with how two-argument cd normally works.
% mkdir ~/tmp/foofoo ~/tmp/foobar
% cdpath=(~/tmp)
% cd ~/tmp/foofoo
% cd foo bar
cd: no such file or directory: /export/home/pws/tmp/barfoo
If it's going to try all possible source matches it should do it in this
case, too. As it is, it always just tries the first match.
This sounds more like an extension for a function. The (I) flag already
handles the special case of an empty string the way you want, so no
special cases within the function.
pws
# should handle options up here...
if (( $# == 2 )); then
local src=$1 rep=$2 dir
integer n=1
while true; do
dir=${(I:${n}:)PWD/$src/$rep}
if [[ $dir = $PWD ]]; then
print -r "$0: no replacements found: $PWD / \"$src\" / \"$rep\"" >&2
return 1
fi
if [[ -d $dir ]]; then
cd -- $dir
return
fi
(( n++ ))
done
else
builtin cd "$@"
fi
Messages sorted by:
Reverse Date,
Date,
Thread,
Author