A simple utility that combines mkdir and cd functionality. Create a directory and immediately change into it with a single command.
mcd <directory_name> [--git|--g] [--code|--c]For example:
mcd bar # Creates 'bar' directory and changes into it
mcd foo/bar/baz # Creates nested directories and changes into 'baz'
mcd project --git # Creates directory and initializes Git repository
mcd project --g # Same as above (short alias)
mcd webapp --code # Creates directory and opens in VS Code
mcd webapp --c # Same as above (short alias)
mcd myapp --git --code # Creates directory, inits Git, and opens in VS Code
mcd myapp --g --c # Same as above (short aliases)--gitor--g: Initialize a Git repository in the newly created directory--codeor--c: Open the newly created directory in Visual Studio Code
Both flags can be used together and work with nested directory paths.
- Creates directories with parent directories as needed (like
mkdir -p) - Immediately changes into the newly created directory
- Error handling for failed directory creation or navigation
- Works with both relative and absolute paths
- Available in both Bash and PowerShell versions
- Optional Git repository initialization with
--gitflag - Optional VS Code integration with
--codeflag - Flags can be combined for complete project setup
-
Run the installation script:
chmod +x install/install.sh ./install/install.sh
-
Restart your terminal or source your profile:
# For zsh (default on macOS) source ~/.zshrc # For bash source ~/.bashrc # For bash on macOS source ~/.bash_profile
-
Verify the installation (optional):
./install/verify.sh
-
Run the installation script:
.\install\install.ps1
-
Restart PowerShell or source the script:
. .\mcd.ps1
- Copy
mcd.shto a directory in your PATH (e.g.,/usr/local/bin/mcd) - Make it executable:
chmod +x /usr/local/bin/mcd - Add to your shell profile:
source /path/to/mcd.sh
-
Add the following line to your PowerShell profile (
$PROFILE):. "/path/to/mcd.ps1"
# Create and enter a simple directory
mcd projects
# Create nested directories
mcd work/client/new-project
# Create directory with Git initialization
mcd my-repo --git
mcd my-repo --g # Short alias
# Create directory and open in VS Code
mcd my-project --code
mcd my-project --c # Short alias
# Create directory with both Git and VS Code
mcd full-setup --git --code
mcd full-setup --g --c # Short aliases
# Use with relative paths
mcd ../sibling-directory --git
# Use with absolute paths
mcd /tmp/test-directory --code# Basic usage
mcd projects
# With Git initialization
mcd my-repo -Git
mcd my-repo -g # Short alias
# With VS Code opening
mcd my-project -Code
mcd my-project -c # Short alias
# With both flags
mcd full-setup -Git -Code
mcd full-setup -g -c # Short aliasesTo test the utility, run the test scripts:
cd tests
./test.shcd tests
.\test.ps1To see all features in action:
cd examples
./demo.shThe utility includes error handling for:
- Missing directory name argument
- Invalid command-line flags
- Failed directory creation (permissions, invalid names, etc.)
- Failed directory navigation
- Missing Git installation (when using
--git) - Missing VS Code CLI installation (when using
--code)
mcd.sh- Bash version of the utilitymcd.ps1- PowerShell version of the utilityinstall/install.sh- Installation script for Bash/Zshinstall/install.ps1- Installation script for PowerShellinstall/verify.sh- Verification script to check installationtests/test.sh- Test script for Bash versiontests/test.ps1- Test script for PowerShell versionexamples/demo.sh- Demo script showing all featuresREADME.md- This documentation
This utility is provided as-is for educational and practical use.