Published on

Automatically CD into a directory after Mkdir

Authors

When I find myself repeating the same set of commands in the shell I try to see if there is some way to alias it to avoid future repetition.

One common pattern is:

mkdir someDir
cd someDir

So I added a zsh/bash function to my .zshrc to do this automatically as below:

function mkdir(){
    command mkdir -p "$1" && cd "$1";
}

The above simply becomes:

mkdir someDir

Note:

  • builtin does not work for mkdir the way it does with cd instead you need to use command as above