zoxide

repository·main·Indexed 13 days ago

https://github.com/ajeetdsouza/zoxide

A smarter cd command for your terminal that learns your habits and tracks frequently visited directories to enable fast navigation via fuzzy matching. Compatible with all major shells, zoxide version 0.10.0 supports interactive selection via fzf and provides subcommands for database management including add, import, query, and remove.

Tokens
9.1K
Snippets
39
Records
56
Agent score
96%

What's inside zoxide

  1. Overview of zoxide

    main
    zoxide is a smarter cd command inspired by z and autojump. It tracks the directories you visit most frequently, allowing you to "jump" to them using just a few keystrokes. It is compatible with all major shells.
  2. Third-party integrations for zoxide

    main

    zoxide integrates with many applications. Some are natively supported, while others require specific plugins.

    Natively Supported

    • Email client: aerc
    • File managers: felix, joshuto, rfm, yazi
    • tmux session managers: sesh, tmux-session-wizard, tmux-sessionx
    • Other: zabb, zesh, zsh-autocomplete

    Plugin Required

    • macOS launchers: alfred (via alfred-zoxide), raycast (via raycast-zoxide)
    • Text editors: emacs (via zoxide.el), vim / neovim (via zoxide.vim), telescope.nvim (via telescope-zoxide)
    • File managers: lf (see wiki), nnn (via nnn-autojump), ranger (via ranger-zoxide), xplr (via zoxide.xplr)
    • Windows: clink (via clink-zoxide)
    • Shell/SSH: xxh (via xxh-plugin-prerun-zoxide)
  3. Install the zoxide binary

    main

    You can install the zoxide binary using a package manager or a shell script depending on your platform.

    Linux / WSL

    • Install script:
    curl -sSfL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh
    • Package Managers:
      • cargo install zoxide --locked (crates.io)
      • conda install -c conda-forge zoxide (conda-forge)
      • brew install zoxide (Linuxbrew)
      • nix-env -iA nixpkgs.zoxide (nixpkgs)
      • apk add zoxide (Alpine Linux 3.13+)
      • pacman -S zoxide (Arch Linux, Manjaro)
      • dnf install zoxide (Fedora 32+)
      • emerge app-shells/zoxide (Gentoo)
      • zypper install zoxide (openSUSE Tumbleweed)
      • pacstall -I zoxide-deb (Rhino Linux)
      • eopkg install zoxide (Solus)
      • xbps-install -S zoxide (Void Linux)

    macOS

    • Package Managers:
      • cargo install zoxide --locked (crates.io)
      • brew install zoxide (Homebrew)
      • conda install -c conda-forge zoxide (conda-forge)
      • port install zoxide (MacPorts)
      • nix-env -iA nixpkgs.zoxide (nixpkgs)
    • Install script:
    curl -sSfL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh

    Windows

    • Recommended:
    winget install ajeetdsouza.zoxide
    • Other Package Managers:
      • cargo install zoxide --locked (crates.io)
      • choco install zoxide (Chocolatey)
      • conda install -c conda-forge zoxide (conda-forge)
      • scoop install zoxide (Scoop)
    • Cygwin, Git Bash, or MSYS2:
    curl -sSfL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh

    BSD

    • Package Managers:
      • cargo install zoxide --locked (crates.io)
      • pkg install zoxide (DragonFly BSD, FreeBSD)
      • pkgin install zoxide (NetBSD)
    • Install script:
    curl -sS https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | bash

    Android (Termux)

    • pkg install zoxide
    • Install script:
    curl -sS https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | bash
    curl -sSfL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh
  4. Exclude directories from the zoxide database

    main
    To permanently exclude specific directories from being added to the zoxide database, set the _ZO_EXCLUDE_DIRS environment variable. This is the preferred method for managing directory exclusion rather than using zoxide remove for individual entries.
  5. How zoxide's ranking and aging algorithms work

    main

    zoxide uses two main concepts to rank directories: Frecency and Aging.

    Frecency

    Frecency is a combination of frequency and recency. Every time a directory is accessed, its score increases. The score is then weighted based on how recently it was accessed:

    • Within the last hour: score * 4
    • Within the last day: score * 2
    • Within the last week: score / 2
    • Otherwise: score / 4

    Aging

    The aging algorithm limits the database size using the _ZO_MAXAGE parameter (default 10000). If the total frecency of all directories exceeds _ZO_MAXAGE, zoxide divides each directory's score by a factor k until the total is approximately 90% of _ZO_MAXAGE. Any directory whose score falls below 1 is removed.

  6. Configure fzf for interactive queries

    main

    When using the --interactive flag, zoxide spawns fzf.

    If you have the FZF_DEFAULT_OPTS environment variable set in your configuration, zoxide will use those options. Otherwise, it defaults to a specific set of arguments designed for a smooth terminal experience:

    --exact
    --no-sort
    --bind=ctrl-z:ignore,btab:up,tab:down
    --cycle
    --keep-right
    --border=sharp
    --height=45%
    --info=inline
    --layout=reverse
    --tabstop=1
    --exit-0

    Note that zoxide also enables fzf preview mode by default.

  7. Initialize zoxide in your shell

    main

    To use zoxide, you must generate and evaluate its shell configuration. The command zoxide init <SHELL> produces the necessary script for your specific shell environment. Follow the instructions below for your shell to add the initialization to your configuration file.

    # Example for Bash
    eval "$(zoxide init bash)"
  8. Initialize zoxide for your shell

    main

    To use zoxide effectively, you must generate and source its shell configuration. Use the zoxide-init subcommand to generate the necessary configuration for your specific shell.

    Note: Any environment variables used for configuration (like _ZO_DATA_DIR or _ZO_ECHO) must be set before calling zoxide-init.

    # Example of how you would typically use it in a shell config (e.g., .bashrc or .zshrc)
    eval "$(zoxide init bash)"
  9. Shell-specific initialization instructions

    main

    Depending on your shell, add the following lines to the end of your configuration file:

    Bash

    File: ~/.bashrc

    eval "$(zoxide init bash)"

    Elvish

    File: ~/.elvish/rc.elv (Requires elvish v0.18.0+)

    eval $(zoxide init elvish | slurp)

    Fish

    File: ~/.config/fish/config.fish

    zoxide init fish | source

    Nushell

    File: Your env file (find via $nu.env-path) and your config file (find via $nu.config-path). Requires Nushell v0.89.0+

    # In your env file:
    zoxide init nushell | save -f ~/.zoxide.nu
    
    # In your config file:
    source ~/.zoxide.nu

    PowerShell

    File: Your profile (find via echo $profile)

    Invoke-Expression (& { (zoxide init powershell | Out-String) })

    Tcsh

    File: ~/.tcshrc

    zoxide init tcsh > ~/.zoxide.tcsh
    source ~/.zoxide.tcsh

    Xonsh

    File: ~/.xonshrc

    execx($(zoxide init xonsh), 'exec', __xonsh__.ctx, filename='zoxide')

    Zsh

    File: ~/.zshrc

    eval "$(zoxide init zsh)"

    Any POSIX shell

    eval "$(zoxide init posix --hook prompt)"
  10. Basic usage of zoxide

    main

    zoxide provides a smarter cd command that uses a ranking algorithm to navigate to frequently used directories. You can use the z command to jump to directories matching specific patterns.

    Common usage patterns:

    • z <pattern>: Jump to the highest ranked directory matching the pattern.
    • z <pattern1> <pattern2>: Jump to the highest ranked directory matching both patterns.
    • z <pattern> /: Jump to a subdirectory starting with the pattern.
    • z <path>: Works like a regular cd command (absolute or relative paths).
    • z ..: Go up one level.
    • z -: Go to the previous directory.
    • zi <pattern>: Interactive selection using fzf to choose from matches.
    z foo              # cd into highest ranked directory matching foo
    z foo bar          # cd into highest ranked directory matching foo and bar
    z foo /             # cd into a subdirectory starting with foo
    z ~/foo             # works like a regular cd command
    z ..                # cd one level up
    z -                 # cd into previous directory
    zi foo              # cd with interactive selection (requires fzf)
  11. Import data from other tools using zoxide import

    main

    The zoxide import command allows you to migrate directory history from other jump tools into the zoxide database.

    Supported Formats:

    • autojump: Imports paths from Autojump. Note that zoxide only imports the paths, not the scores, because the matching algorithms differ.
    • z: Used for fasd, z, z.lua, or zsh-z databases.

    Behavior and Merging:

    • By default, the import will fail if the existing zoxide database is not empty.
    • To add the imported data to your existing zoxide history instead of replacing it, use the --merge flag.
    zoxide import PATH --from FORMAT [OPTIONS]
    
    # Example: Merging autojump data
    zoxide import ~/.autojump_history --from autojump --merge