Skip to content

ToB213/mkcd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mkcd

mkdir + cd in one command — create a directory and jump right into it.
See usage »

Report a Bug · Request a Feature

MIT License Rust


Table of Contents


About

$ mkcd projects/rust/new-tool
# → creates ~/projects/rust/new-tool and cd's into it

Tired of typing mkdir -p foo/bar && cd foo/bar? mkcd collapses that into a single command. It supports nested paths, absolute paths, and bash / zsh / fish.

Highlights:

  • Creates nested directories in one shot (mkdir -p equivalent)
  • Automatically cds into the created directory
  • Works with both absolute and relative paths
  • Can cd into directories that already exist
  • Supports permission flags (-m)
  • Integrates with zoxide automatically

(back to top)


Built With

Rust

Crate Purpose
clap CLI argument parsing
anyhow Error handling

(back to top)


Installation

Prerequisites

A Rust toolchain is required.

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

1. Build and install the binary

cargo install --git https://github.com/ToB213/mkcd

2. Set up shell integration

Add one line to your shell's config file.

bash (~/.bashrc):

eval "$(mkcd-bin --init bash)"

zsh (~/.zshrc):

eval "$(mkcd-bin --init zsh)"

fish (~/.config/fish/config.fish):

mkcd-bin --init fish | source

Reload your shell and mkcd is ready to use.

(back to top)


Usage

# Create a nested directory and cd into it
mkcd foo/bar/baz

# Works with absolute paths too
mkcd /tmp/work/session

# cd into an existing directory
mkcd path/that/already/exists

# Create with specific permissions
mkcd -m 700 secret/dir

Options

Option Description
-p, --parents Create parent directories as needed (enabled by default)
-m, --mode <MODE> Set permissions in octal (e.g. 700)
--init <SHELL> Print the shell integration function (bash / zsh / fish)

(back to top)


How It Works

cd is a shell builtin — a child process cannot change the working directory of its parent shell. mkcd works around this with a two-layer design:

mkcd foo/bar
  └─ shell function mkcd()
       └─ mkcd-bin foo/bar  →  creates the directory, prints absolute path to stdout
            └─ cd /abs/path/foo/bar

The binary (mkcd-bin) is responsible only for creating the directory and printing the absolute path. The shell function receives that path and calls cd.

(back to top)


Roadmap

  • Publish to crates.io
  • Windows support
  • Snapshot tests for --init output
  • Expand integration test coverage

Open an issue to report bugs or suggest features.

(back to top)


Contributing

Contributions are welcome!

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

(back to top)


License

Distributed under the MIT License. See LICENSE for details.

(back to top)


Contact

Project Link: https://github.com/ToB213/mkcd

(back to top)


About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors