Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: -C -like option to change CWD on startup
- X-seq: zsh-workers 51346
- From: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>
- To: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: -C -like option to change CWD on startup
- Date: Thu, 2 Feb 2023 10:05:10 +0100
- Archived-at: <https://zsh.org/workers/51346>
- In-reply-to: <CAKc7PVDN+HfQ=qFatNcWFiNRiTMtpAi6FXhXNqdQ1SRxHj1vcw@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAKc7PVDN+HfQ=qFatNcWFiNRiTMtpAi6FXhXNqdQ1SRxHj1vcw@mail.gmail.com>
On Thu, Feb 2, 2023 at 9:57 AM Sebastian Gniazdowski
<sgniazdowski@xxxxxxxxx> wrote:
>
> Hi,
> make and git have the -C option which works like:
> (
> builtin cd -q $COPT
> git/make "$@"
> )
>
> I think that it is very useful, because no lengthy subshell is needed. Zsh doesn't have such option, could it be added? It's pitty that -C is already used by NO_CLOBBER, but maybe some other letter is free (I didn't found any)?
You can do this:
zsh-in-dir() ( builtin cd -q -- "$1" && builtin exec zsh "${@:2}" )
This forks and execs once, the same as if there was a native `-C dir` option.
Note that your original code has the same performance thanks to an
optimization in zsh. The second fork is elided.
Roman.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author