Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Creating function in zsh
- X-seq: zsh-users 13336
- From: Stephane Chazelas <Stephane_Chazelas@xxxxxxxx>
- To: czech@xxxxxxxxx
- Subject: Re: Creating function in zsh
- Date: Thu, 16 Oct 2008 21:11:54 +0100
- Cc: zsh-users@xxxxxxxxxx
- In-reply-to: <5956.148.87.1.170.1224187179.squirrel@xxxxxxxxxxxxxxxxx>
- Mail-followup-to: czech@xxxxxxxxx, zsh-users@xxxxxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <5956.148.87.1.170.1224187179.squirrel@xxxxxxxxxxxxxxxxx>
On Thu, Oct 16, 2008 at 12:59:39PM -0700, czech@xxxxxxxxx wrote:
> Hi -
>
> I have created the following function in zsh on Mac OSX:
>
> cd() {
> builtin cd "$@" print -D $PWD
> }
>
> This works find on OSX, but gives the following error on Fedora Core 8:
>
> johann:czechar:.zfunc> cd /home/czechar
> cd /home/czechar
> cd:cd:1: too many arguments
>
> I am running zsh 4.2.6 on Fedora.
>
> Any notion what the problem could be?
[...]
I doubt it works on MaxOSX. You're not separating the two
commands, so "print", "-D" and $PWD are treated as arguments to
"builtin cd".
cd() {
builtin cd "$@" &&
print -rD $PWD
}
"&&" as you probably want to print the current directory only if
cd succeeds.
You need -r, as you don't want \x sequences to be expanded.
If you want to print the directory regardless of whether cd
succeeds, you should at least make sure you return cd's exit
status:
cd() {
local ret
builtin cd "$@"
ret=$?
print -rD $PWD
return $ret
}
--
Stéphane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author