Skip to content

edwardjensen/make-change-directory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mcd - Make Directory and Change Directory

A simple utility that combines mkdir and cd functionality. Create a directory and immediately change into it with a single command.

Usage

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)

Flags

  • --git or --g: Initialize a Git repository in the newly created directory
  • --code or --c: Open the newly created directory in Visual Studio Code

Both flags can be used together and work with nested directory paths.

Features

  • 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 --git flag
  • Optional VS Code integration with --code flag
  • Flags can be combined for complete project setup

Installation

For Bash/Zsh (macOS/Linux)

  1. Run the installation script:

    chmod +x install/install.sh
    ./install/install.sh
  2. 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
  3. Verify the installation (optional):

    ./install/verify.sh

For PowerShell

  1. Run the installation script:

    .\install\install.ps1
  2. Restart PowerShell or source the script:

    . .\mcd.ps1

Manual Installation

Bash Version

  1. Copy mcd.sh to a directory in your PATH (e.g., /usr/local/bin/mcd)
  2. Make it executable: chmod +x /usr/local/bin/mcd
  3. Add to your shell profile: source /path/to/mcd.sh

PowerShell Version

  1. Add the following line to your PowerShell profile ($PROFILE):

    . "/path/to/mcd.ps1"

Examples

# 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

PowerShell Examples

# 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 aliases

Testing

To test the utility, run the test scripts:

Bash Test

cd tests
./test.sh

PowerShell Test

cd tests
.\test.ps1

Demo Script

To see all features in action:

cd examples
./demo.sh

Error Handling

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

Files

  • mcd.sh - Bash version of the utility
  • mcd.ps1 - PowerShell version of the utility
  • install/install.sh - Installation script for Bash/Zsh
  • install/install.ps1 - Installation script for PowerShell
  • install/verify.sh - Verification script to check installation
  • tests/test.sh - Test script for Bash version
  • tests/test.ps1 - Test script for PowerShell version
  • examples/demo.sh - Demo script showing all features
  • README.md - This documentation

License

This utility is provided as-is for educational and practical use.

About

Utility to create and change to the new directory

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published