mkdcd
v0.1.0
Published
Tiny mkdir + cd shortcut: make a directory (recursively) and cd into it.
Maintainers
Readme
mkdcd
mkdir + cd in one tiny command. Create a directory (recursively when the
path is nested) and step into it — no more mkdir foo && cd foo.
$ mkdcd projects/app/src
created projects/app/src
$ pwd
/home/you/projects/app/src- Tiny: one POSIX
shscript, no compilation, no dependencies. - Cross-platform: Linux + macOS, works in bash, zsh, and fish.
- Recursive by default; choose to land on the leaf or the newly-created root.
How it works (the one thing to know)
A program can't change your shell's current directory — only the shell can.
So mkdcd comes in two parts:
- a binary (
mkdcd) that does themkdir -pand prints the target path, and - a shell function that runs the binary and
cds into whatever it printed.
You install the binary once, then add one line to your shell rc to enable the
cd part. Without that line, mkdcd still creates the directory and prints its
path — it just won't move your shell.
Install
Homebrew (macOS / Linux)
brew install Abdelhak-Bahri/tap/mkdcd
# or, from the formula in this repo:
brew install --formula ./Formula/mkdcd.rbnpm
npm install -g mkdcdDebian / Ubuntu (apt / .deb)
# grab the .deb from Releases, then:
sudo apt install ./mkdcd_0.1.0_all.deb
# (build one yourself with: nfpm package -p deb — see "Build a package" below)curl one-liner
curl -fsSL https://raw.githubusercontent.com/Abdelhak-Bahri/mkdcd/main/install.sh | shBuild from source
There's nothing to compile — it's a script. Just install it:
git clone https://github.com/Abdelhak-Bahri/mkdcd
cd mkdcd
make install # -> ~/.local/bin/mkdcd (no root)
sudo make install PREFIX=/usr/local # system-wideEnable the cd (shell integration)
Add the matching line to your shell config, then restart your shell:
# bash (~/.bashrc)
eval "$(mkdcd init bash)"
# zsh (~/.zshrc)
eval "$(mkdcd init zsh)"
# fish (~/.config/fish/config.fish)
mkdcd init fish | source(Or source the shipped mkdcd.sh / mkdcd.fish files directly.)
Usage
mkdcd [OPTIONS] <dir>
mkdcd init <bash|zsh|fish|posix>| Option | Meaning |
| ---------------- | ------------------------------------------------------------- |
| -l, --leaf | cd into the deepest created directory (default) |
| -r, --root | cd into the shallowest newly-created directory |
| -q, --quiet | suppress the "created" message |
| -h, --help | show help |
| -v, --version | show version |
Examples
mkdcd app # create ./app, cd into it
mkdcd a/b/c # create a/b/c, cd into a/b/c (leaf)
mkdcd -r a/b/c # create a/b/c, cd into 'a' (new root)
mkdcd "logs $(date +%F)" # spaces are fine when quotedLeaf vs. root: for mkdcd a/b/c where a already exists but b and c are
new, --leaf lands you in a/b/c, while --root lands you in a/b (the topmost
directory this command actually created).
Build a package (maintainers)
Uses nfpm to build .deb and .rpm from the
same config:
nfpm package -f nfpm.yaml -p deb # -> mkdcd_0.1.0_all.deb
nfpm package -f nfpm.yaml -p rpmTest
make check # or: sh test/test.shUninstall
make uninstall # if installed via make
npm uninstall -g mkdcd # if installed via npm
brew uninstall mkdcd # if installed via brew
rm ~/.local/bin/mkdcd # if installed via curlThen remove the mkdcd init … line from your shell rc.
License
MIT — see LICENSE.
