Skip to content

Simpler than fzf, more predictable than zoxide, perfect for JavaScript monorepos when cd-ing into monorepo workspace directories.

License

Notifications You must be signed in to change notification settings

omranjamal/mono-cd

Repository files navigation

mono-cd

GitHub Release Date GitHub Release GitHub Issues or Pull Requests

The quickest way to cd into a workspace folder inside a JavaScript monorepo. It's simpler than fzf, more predictable than zoxide (zi), and specifically created for JavaScript monorepos.

DEMO

Features

  1. cd into any of the folders in a JavaScript monorepo
  2. Support for both interactive and non-interactive modes
  3. Support for
    1. pnpm workspaces
    2. npm workspaces
    3. yarn workspaces
    4. Custom directories via .monocdrc.json
  4. Support for non-javascript monorepos, also via .monocdrc.json
  5. Works inside Docker containers. (Tested with Alpine and Debian images)
  6. Tested on Linux & MacOS

Installation

curl -L "https://github.com/omranjamal/mono-cd/releases/latest/download/install.sh" | sh -

Usage

# interactive mode:
mcd

# non interactive `cd` if only one match is present.
mcd [search]
  • Up / Down to select a directory.
  • Starting typing to filter list of directories.
  • Vim keybindings are also available, i.e. Ctrl+N/P is save as Up and Down

The .monocdrc.json File (Optional)

This is a configuration file which you place at the root of your monorepo. You can use to include workspaces or exclude workspaces from being searched for workspaces.

Example

{
   "$schema": "https://raw.githubusercontent.com/omranjamal/mono-cd/refs/heads/main/monocdrc-schema.json",
   "workspaces": [
      "another_folder/*",
      "!another_folder/but_not_this_one"
   ],
   "exclude": [
      "dont_even_try/to_match_in_this_folder"
   ]
}

Limiting Height

By default mono-cd will take us at most the number of rows available in your terminal, but if you want to override that to a fixed number of rows, set MONOCD_MAX_HEIGHT to a number such as:

# ~/.bashrc
export MONOCD_MAX_HEIGHT=12

Install Inside Docker

Docker installation has been tested with alpine and debian images. To install in docker, add the following line to your Dockerfile

RUN wget -qO - https://github.com/omranjamal/mono-cd/releases/latest/download/docker-install.sh | sh -

IMPORTANT: Start as Login Shell

mono-cd adds the mcd command to ~/.profile when installing inside Docker. Make sure to start your shell as a login shell to ensure the ~/.profile is loaded.

Shells can be started as login shells typically with the -l flag as such:

bash -l   # ideal for debian images
sh -l     # works across most images, ideal for alpine images

Manual Installation

# Create installation directory
mkdir -p ~/.local/share/omranjamal/mono-cd

# Download the binary (check releases page for all available binaries)
wget -O ~/.local/share/omranjamal/mono-cd/mono-cd https://github.com/omranjamal/mono-cd/releases/latest/download/mono_amd64

# Add execution permissions
chmod +x ~/.local/share/omranjamal/mono-cd/mono-cd

# Add to shell (assuming you're using bash)
~/.local/share/omranjamal/mono-cd/mono-cd --install ~/.bashrc

Setting Different Alias

You can either change the function name in your ~/.bashrc / ~/.zshrc / ~/.profile file from mcd to something else.

OR, you could add the alias in Step 4 from above by passing as the last argument.

~/.local/share/omranjamal/mono-cd/mono-cd --install ~/.bashrc monocd

monocd being the different alias that you want.

Development

git clone git@github.com:omranjamal/mono-cd.git

cd ./mono-cd

go get
go run main.go

License

MIT

Related

mono-cd is actually based on bookmark-cd a similar project aimed at cd-ing into bookmarked folders a breeze.

About

Simpler than fzf, more predictable than zoxide, perfect for JavaScript monorepos when cd-ing into monorepo workspace directories.

Resources

License

Stars

Watchers

Forks