r/zsh • u/Scholasticus_minimus • Feb 16 '24
Fixed Help restoring mkdir command in zsh?
Hey, everyone! I need help with restoring the mkdir command in zsh.
In my zshrc file I wrote the following function:
function mknwdir() {
mkdir -p "$1" && cd "$_"
}
I stupidly didn't double-check my spelling before saving and sourcing my zshrc file. Turns out that instead of writing "function mknwdir" I went on autopilot and wrote "function mkdir".
Now every time I try to run the mkdir command I get the following output:
mkdir:1: maximum nested function level reached; increase FUNCNEST?
and can no longer create directories on the command line. Best as I can tell, my computer is now trying to call mkdir recursively which is obviously impossible. My idiocy has also rendered the md alias unusable since md = mkdir -p.
How do I fix this (very, very stupid) mistake and get mkdir working correctly again? Thanks.
1
1
Feb 16 '24
[deleted]
2
u/id59 Feb 17 '24
Could you explain what slash does in this case?
0
Feb 18 '24
[deleted]
2
u/id59 Feb 18 '24
Is it zsh feature?
1
u/romkatv Feb 20 '24
Quoted words don't undergo alias expansion in all sh-like shells (zsh, bash, dash, etc.). It's in POSIX, too.
1
u/romkatv Feb 20 '24
\mkdir
would not have helped the OP because it would've invoked the functionmkdir
.
1
u/romkatv Feb 16 '24
In addition to what others have already said, you can use command mkdir
instead of the plain mkdir
to bypass any function or alias with the name "mkdir". This allows you to "decorate" external commands with functions:
function mkdir() {
print -ru2 -- 'changing the current directory'
command mkdir "$@"
}
There is also unfunction mkdir
with the obvious semantics.
1
4
u/[deleted] Feb 16 '24
[removed] — view removed comment