8000 GitHub - ikko/cdc: cd by name to the newest copy: project, project.1, project.2 → the one you work in now (bash, zsh) · GitHub
[go: up one dir, main page]

Skip to content
ikkoPublic

About

cd by name to the newest copy: project, project.1, project.2 → the one you work in now (bash, zsh)

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

cdc – change directory to the Current one

cd by name to the newest copy: project, project.1, project.2 → the one you work in now.

  • cdc name jumps to the newest directory called name or name.* anywhere below your home.
  • No training, no database to warm up: it works on the first call.
~$ cdc project            # -> ~/code/project.2   (newest of project, project.1, project.2)
~$ cdc project.1          # -> ~/code/project.1   (exact name)
~$ cdc . build            # search only below the current directory
~$ cdc -g src             # search from the git root
~$ cdc -                  # back in history;  cdc +  forward
~$ cdc pro<TAB>           # complete names from a live scan

Why not zoxide, autojump, z?

  • They return where you went most often.
  • cdc returns what exists, newest first, so
    • a fresh clone or project.3 wins immediately, and
    • a tree you never visited works too.
  • Both kinds can coexist.

Install

curl -fsSL https://raw.githubusercontent.com/ikko/cdc/main/install.sh | bash

Then open a new shell.

  • Works in bash (≥ 4.4) and zsh: the installer sets up each one you have.
  • It tells you if something else in your shell is already called cdc.
  • It installs the latest release:
    • prebuilt for Linux and macOS, no Rust needed;
    • where no binary fits, it builds with cargo.
  • Updating and removing: below.

With apt on Debian, Ubuntu (amd64, arm64):

  • the package holds the engine and the man page;
  • a package cannot edit your rc file, so the last line is yours.

Either the .deb:

curl -fsSLO "https://github.com/ikko/cdc/releases/latest/download/cdc_$(dpkg --print-architecture).deb"
sudo apt install "./cdc_$(dpkg --print-architecture).deb"
echo 'eval "$(cdc-scan init bash)"' >>~/.bashrc
# zsh: echo 'eval "$(cdc-scan init zsh)"' >>~/.zshrc

or the signed apt repository, which apt upgrade then keeps current:

sudo install -d /etc/apt/keyrings
sudo curl -fsSLo /etc/apt/keyrings/cdc.asc https://ikko.github.io/cdc/cdc.asc
printf 'Types: deb\nURIs: https://ikko.github.io/cdc\nSuites: stable\nComponents: main\nSigned-By: /etc/apt/keyrings/cdc.asc\n' | sudo tee /etc/apt/sources.list.d/cdc.sources
sudo apt update && sudo apt install cdc
echo 'eval "$(cdc-scan init bash)"' >>~/.bashrc
  • The key's fingerprint: C8A3 7DED E5B6 84FC 85EA 32D4 5946 7FD3 DB4B 699D; check it after the download with gpg --show-keys /etc/apt/keyrings/cdc.asc.
  • tests/e2e/apt.sh runs these lines against a local signed repository: install, apt upgrade, a wrong key refused.

From source without the installer:

  • cargo build --release in scanner/ (Rust ≥ 1.80, no dependencies);
  • put cdc-scan on your PATH;
  • add eval "$(cdc-scan init bash)" to ~/.bashrc (zsh: eval "$(cdc-scan init zsh)" to ~/.zshrc).

Usage

Command Effect
cdc <name> cd to the newest dir named <name> or <name>.* below $CDC_ROOT (default $HOME)
cdc [from] <name> search below from instead (., .., ~/code, any path)
cdc -r <name> rescan: ignore the cache (finds dirs created since the last lookup)
cdc -g <name> search from the git repository root
cdc -v ... say how the answer was found: from the cache, or by a walk (threads, dirs, time)
cdc -p ... print the directory landed in, like pwd (also with -, +)
cdc -u [...] update cdc, then run the rest (see Update)
cdc pick from history and cache with fzf
cdc - / cdc + back / forward in history (shared by all shells)
cdc -l [substr] · cdc -H [n] · cdc -i list cache · history · ignore globs
cdc -h · man cdc full reference
cdc -- <name> a name starting with -

fzf is optional. Only a bare cdc (the picker) needs it; without fzf it prints the usage line. cdc does not install it; when fzf is missing, the installer prints the command for your system (e.g. sudo apt install fzf, brew install fzf). It works at once, also in shells already open (test fzf-late).

Lookups are cached (milliseconds); a miss, or a name not walked for a day, walks the tree in parallel. A new sibling of a cached match (project.3 next to project.2) is seen at once. node_modules, .git, .venv and other package and build caches are skipped; add your own globs to ~/.cdcignore. Only directories owned by you or root can be the answer, so nobody can plant a newer build in a shared tree for you; yours below a colleague's directory count when its group is one of your supplementary groups. Ctrl-C leaves you where you were.

Setting Effect
CDC_ROOT default search root (default $HOME)
CDC_XDEV=1 do not enter other filesystems (NFS, sshfs)
CDC_TTL hours a walk keeps the cache trusted for its name (default 24, 0 = always)
CDC_ANY_OWNER=1 accept directories of other users
CDC_PRINT=1 always print the directory landed in (as -p)

Switches (=1) are off when unset, empty or 0.

cdc in five lines of bash

The whole idea fits in a shell function (GNU find; the test suite checks that it lands where cdc does). The table below shows what the real tool adds.

cdc() {   # the core of cdc: the newest dir named $1 or $1.* below $HOME
  local d; d=$(find ~ -type d \( -name "$1" -o -name "$1.*" \) -printf '%T@\t%p\n' 2>/dev/null |
               sort -rn | head -n1 | cut -f2-)
  [ -n "$d" ] && cd -- "$d"
}
The five lines cdc
walk all of ~ on every call (cdc's find predecessor: 2.5 s) cache: milliseconds; a miss walks in parallel: 0.2 s (speed)
enter node_modules, .git, .venv, … skip package stores and build caches; your globs in ~/.cdcignore
$1 is a pattern: cdc 'a*' matches abc the name is taken literally: a* is a directory called a*
anyone's directory can win (/tmp/build) only yours or root's, and not below a stranger's directory (a shared project group makes a colleague's fine)
GNU only; equal times: any order; cdc café misses a café whose é is stored as e + accent (macOS copies) macOS too; equal times: by path; an accented letter matches in both stored forms
that is all history -/+ across shells, fzf picker, TAB completion, -g, -r, -u

Platforms

Prebuilt, checksummed binaries for

  • Linux
    • x86_64, aarch64: glibc and static musl;
    • armv7 (32-bit Raspberry Pi OS) and riscv64: tested under emulation only;
  • macOS
    • x86_64, arm64: tested on macOS 15 (Intel) and macOS 26 (Apple Silicon).

Elsewhere the installer builds with cargo. On Windows use WSL.

Update and uninstall

Update

  • cdc -u fetches the latest release (with curl or wget), installs it in place and loads it into the running shell; cdc -u <name> then jumps.
  • Rerunning the install line does the same: it finds the existing install (also one made with --prefix) and updates it, never a second copy beside it.
  • A package updates with its manager.

Uninstall

  • bash ~/.local/share/cdc/install.sh --uninstall removes the install directory and cdc's block from your rc files. Nothing else was written.
  • It keeps your data and names it: the cache, history and walk records (~/.local/cdc.dirs, cdc.history, cdc.walks) and ~/.cdcignore.
    • --uninstall --purge removes these four as well.
    • Later, when install.sh is gone: curl -fsSL https://raw.githubusercontent.com/ikko/cdc/main/install.sh | bash -s -- --uninstall --purge
  • A package:
    • sudo apt remove cdc, then delete the eval "$(cdc-scan init …)" line from your rc file;
    • with the repository also sudo rm /etc/apt/sources.list.d/cdc.sources /etc/apt/keyrings/cdc.asc;
    • a package never touches a home directory, so the four files stay until you delete them.

Details: docs/DETAILS.md#installsh.

More

Licence: Apache-2.0, © 2026 Miklos Beky miklos.beky@gmail.com (NOTICE).

About

cd by name to the newest copy: project, project.1, project.2 → the one you work in now (bash, zsh)

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0