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

-- 
Stephane


Reply via email to