coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFE] mkdir w/chdir


From: Vito Caputo
Subject: Re: [RFE] mkdir w/chdir
Date: Tue, 3 Sep 2019 14:00:29 -0700
User-agent: NeoMutt/20170113 (1.7.2)

On Tue, Sep 03, 2019 at 09:28:00PM +0100, Stephane Chazelas wrote:
> 2019-09-03 13:12:25 -0700, Vito Caputo:
> [...]
> > Lately I've been finding myself wishing there were a flag for mkdir to
> > cd into the directory, especially in combination with creating parents.
> > 
> > It's like I'm already thinking in convenient shortcut mode asking for
> > parents to be created and just want to throw another flag in there to
> > switch my directory as well in the same command.
> > 
> > i.e.
> > short: mkdir -pc /foo
> > long: mkdir --parents --chdir /foo
> > 
> > Any chance of getting this in or too creepy?
> [...]
> 
> The current working directory is a property of each process,
> only a shell builtin command can change the working directory of
> the shell.
> 
> GNU coreutils is a set of standalone utilities, they cannot
> change the working directory of the shell process because they
> run in their own separate process.
> 
> A shell builtin mkdir command like that of zsh, sash or busybox
> or ksh93 could be modified to have an option to cd into the
> created directory, but GNU coreutils mkdir cannot.
> 
> Here, if using a POSIX-like shell, you would probably want to
> create a shell function for it like:
> 
> mkcd() {
>   mkdir "$@" &&
>     shift "$(($# - 1))" &&
>     CDPATH= cd -P -- "$1"
> }
> 
> (beware it doesn't work properly for "mkcd -" or other special
> strings that some shells treat specially).
> 

Thanks (everyone) for the quick response, that's an obvious limitation
with mkdir in a separate process.  I should have mailed the bash mailing
list.

It's trivial to add locally, but the real value would be for it to be
something omnipresent in the future, not just on my personal snowflake
machines.  Getting it in bash might be good enough though.

Regards,
Vito Caputo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]