zsh-workers
 help / color / mirror / code / Atom feed
* -C -like option to change CWD on startup
@ 2023-02-02  8:55 Sebastian Gniazdowski
  2023-02-02  9:05 ` Roman Perepelitsa
  0 siblings, 1 reply; 3+ messages in thread
From: Sebastian Gniazdowski @ 2023-02-02  8:55 UTC (permalink / raw)
  To: Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 368 bytes --]

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)?

-- 
Best regards,
Sebastian Gniazdowski

[-- Attachment #2: Type: text/html, Size: 1133 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: -C -like option to change CWD on startup
  2023-02-02  8:55 -C -like option to change CWD on startup Sebastian Gniazdowski
@ 2023-02-02  9:05 ` Roman Perepelitsa
  2023-02-02  9:31   ` Sebastian Gniazdowski
  0 siblings, 1 reply; 3+ messages in thread
From: Roman Perepelitsa @ 2023-02-02  9:05 UTC (permalink / raw)
  To: Sebastian Gniazdowski; +Cc: Zsh hackers list

On Thu, Feb 2, 2023 at 9:57 AM Sebastian Gniazdowski
<sgniazdowski@gmail.com> 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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: -C -like option to change CWD on startup
  2023-02-02  9:05 ` Roman Perepelitsa
@ 2023-02-02  9:31   ` Sebastian Gniazdowski
  0 siblings, 0 replies; 3+ messages in thread
From: Sebastian Gniazdowski @ 2023-02-02  9:31 UTC (permalink / raw)
  To: Roman Perepelitsa; +Cc: Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 1177 bytes --]

thanks for the interesting example. I would want to note two other programs
that follow -C option convention, namely tar and env. The second can be
even used to workaround the problem, i.e.:

env -C ~/github zsh -c 'some commands'

but still, a dedicated option would be good.

On Thu, 2 Feb 2023 at 09:05, Roman Perepelitsa <roman.perepelitsa@gmail.com>
wrote:

> On Thu, Feb 2, 2023 at 9:57 AM Sebastian Gniazdowski
> <sgniazdowski@gmail.com> 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.
>


-- 
Best regards,
Sebastian Gniazdowski

[-- Attachment #2: Type: text/html, Size: 2187 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-02-02  9:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-02  8:55 -C -like option to change CWD on startup Sebastian Gniazdowski
2023-02-02  9:05 ` Roman Perepelitsa
2023-02-02  9:31   ` Sebastian Gniazdowski

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).