# cd directly to a folder

> Speed up folder navigation.

Tab completion and unambiguous folder names make navigating to a Johnny.Decimal folder trivial.

```zsh
cd 2⇥ 21⇥ 21.13⇥⏎
# /Users/john/Documents/20-29 Create & collect/21 Imaginarium 🧠/21.13 Flight records & boarding passes
```

That gets you to folder `21.13` by way of `20-29` then `21`. Pretty quick, but we can make it quicker.

Add this to `~/.zshrc`.

```zsh
# ⚠️ Set your own path
export JD_PATH="/Users/john/Documents"

jd() {
  local root="${JD_PATH:?JD_PATH not set}" id="$1"
  if [[ -z "$id" ]]; then
    cd "$root"
    return
  fi
  local match
  match=$(find "$root" -maxdepth 3 -type d -name "$id *" -print -quit)
  if [[ -n "$match" ]]; then
    cd "$match"
  else
    echo "No folder found for $id" >&2
    return 1
  fi
}

# Extension for multiple systems
# ⚠️ Set your own paths
export JD_D25_PATH="/Users/john/Documents/D25"
export JD_P76_PATH="/Users/john/Documents/P76"

d25() { JD_PATH="$JD_D25_PATH" jd "$@" }
p76() { JD_PATH="$JD_P76_PATH" jd "$@" }
```

## Usage

### Single systems

```zsh
jd 21.13
# /Users/john/Documents/20-29 Create & collect/21 Imaginarium 🧠/21.13 Flight records & boarding passes
```

### Multiple systems

```zsh
p76 21.13
pwd
# /Users/john/Documents/P76/20-29 Create & collect/21 Imaginarium 🧠/21.13 Flight records & boarding passes
```

## Note: the CLI is also `jd`

The in-development [CLI utility](/jdhq/jd/) will eventually perform this function. If you want to try the CLI, give the function described above a different name (e.g. `jdcd`).