zoxide/README.md

383 lines
14 KiB
Markdown
Raw Normal View History

2021-09-17 19:59:46 +00:00
<!-- markdownlint-configure-file {
"MD013": {
"code_blocks": false,
"tables": false
},
"MD033": false
} -->
2021-07-21 19:07:20 +00:00
2021-04-11 20:26:48 +00:00
# `zoxide`
2020-03-07 21:04:47 +00:00
2021-05-05 23:01:57 +00:00
> A smarter cd command for your terminal
2020-03-07 21:04:47 +00:00
2021-09-06 20:54:11 +00:00
[![crates.io][crates.io-badge]][crates.io]
[![Downloads][downloads-badge]][releases]
[![Built with Nix][builtwithnix-badge]][builtwithnix]
2021-05-01 21:56:12 +00:00
2021-04-11 20:26:48 +00:00
`zoxide` is a blazing fast replacement for your `cd` command, inspired by
2021-09-06 20:54:11 +00:00
`z` and `autojump`. It keeps track of the directories you use most
2021-04-11 20:26:48 +00:00
frequently, and uses a ranking algorithm to navigate to the best match.
2020-03-07 21:04:47 +00:00
2021-05-15 04:13:55 +00:00
![Tutorial][tutorial]
2020-05-29 23:38:30 +00:00
2020-03-07 21:04:47 +00:00
## Examples
```sh
2021-04-12 20:27:36 +00:00
z foo # cd into highest ranked directory matching foo
z foo bar # cd into highest ranked directory matching foo and bar
2020-03-07 21:04:47 +00:00
2021-04-12 20:27:36 +00:00
z ~/foo # z also works like a regular cd command
z foo/ # cd into relative path
z .. # cd one level up
z - # cd into previous directory
2020-03-07 21:04:47 +00:00
2021-04-12 20:27:36 +00:00
zi foo # cd with interactive selection (using fzf)
2020-03-07 21:04:47 +00:00
```
2021-04-11 20:26:48 +00:00
Read more about the matching algorithm [here][algorithm-matching].
2020-03-07 21:04:47 +00:00
## Getting started
### *Step 1: Install `zoxide`*
2020-03-07 21:04:47 +00:00
`zoxide` runs on most major platforms. If your platform isn't listed below,
2021-07-21 19:07:20 +00:00
please [open an issue][issues].
<details>
<summary>Linux</summary>
To install `zoxide`, run this command in your terminal:
2020-07-26 16:39:24 +00:00
2021-06-17 08:50:51 +00:00
```sh
curl -sS https://webinstall.dev/zoxide | bash
```
2021-07-21 19:07:20 +00:00
Alternatively, you can use a package manager:
| Distribution | Repository | Instructions |
| ------------------ | ----------------------- | ---------------------------------------------------------------------------------------------- |
2021-08-05 08:52:12 +00:00
| ***Any*** | **[crates.io]** | `cargo install zoxide` |
2021-07-21 19:07:20 +00:00
| *Any* | [conda-forge] | `conda install -c conda-forge zoxide` |
| *Any* | [Linuxbrew] | `brew install zoxide` |
| Alpine Linux 3.13+ | [Alpine Linux Packages] | `apk add zoxide` |
| Arch Linux | [Arch Linux Community] | `pacman -S zoxide` |
2021-07-21 19:07:20 +00:00
| CentOS 7+ | [Copr] | `dnf copr enable atim/zoxide` <br /> `dnf install zoxide` |
2021-08-30 08:19:18 +00:00
| Debian 11+ | [Debian Packages] | `apt install zoxide` |
2021-07-21 19:07:20 +00:00
| Devuan 4.0+ | [Devuan Packages] | `apt install zoxide` |
| Fedora 32+ | [Fedora Packages] | `dnf install zoxide` |
| Gentoo | [GURU Overlay] | `eselect repository enable guru` <br /> `emerge --sync guru` <br /> `emerge app-shells/zoxide` |
2021-08-30 08:19:18 +00:00
| Manjaro | | `pacman -S zoxide` |
2021-07-21 19:07:20 +00:00
| NixOS | [nixpkgs] | `nix-env -iA nixpkgs.zoxide` |
| Parrot OS | | `apt install zoxide` |
2021-08-30 08:19:18 +00:00
| Raspbian | | `apt install zoxide` |
2021-07-21 19:07:20 +00:00
| Ubuntu 21.04+ | [Ubuntu Packages] | `apt install zoxide` |
| Void Linux | [Void Linux Packages] | `xbps-install -S zoxide` |
</details>
<details>
<summary>macOS</summary>
2021-07-29 06:59:41 +00:00
To install `zoxide`, use a package manager:
2020-03-07 21:04:47 +00:00
| Repository | Instructions |
| --------------- | ------------------------------------- |
2021-08-05 08:52:12 +00:00
| **[crates.io]** | `cargo install zoxide` |
| [conda-forge] | `conda install -c conda-forge zoxide` |
| [Homebrew] | `brew install zoxide` |
| [MacPorts] | `port install zoxide` |
2020-03-07 21:04:47 +00:00
2021-07-21 19:07:20 +00:00
</details>
<details>
<summary>Windows</summary>
To install `zoxide`, run this command in your command prompt:
```sh
curl.exe -A "MS" https://webinstall.dev/zoxide | powershell
```
Alternatively, you can use a package manager:
2020-05-24 21:25:00 +00:00
| Repository | Instructions |
| --------------- | ------------------------------------- |
2021-08-05 08:52:12 +00:00
| **[crates.io]** | `cargo install zoxide` |
| [Chocolatey] | `choco install zoxide` |
| [conda-forge] | `conda install -c conda-forge zoxide` |
| [Scoop] | `scoop install zoxide` |
2020-03-07 21:04:47 +00:00
2021-07-21 19:07:20 +00:00
</details>
<details>
<summary>BSD</summary>
To install `zoxide`, use a package manager:
2020-03-07 21:04:47 +00:00
| Distribution | Repository | Instructions |
| ------------- | --------------- | ---------------------- |
2021-08-05 08:52:12 +00:00
| ***Any*** | **[crates.io]** | `cargo install zoxide` |
| DragonFly BSD | [DPorts] | `pkg install zoxide` |
| FreeBSD | [FreshPorts] | `pkg install zoxide` |
| NetBSD | [pkgsrc] | `pkgin install zoxide` |
2020-05-24 21:25:00 +00:00
2021-07-21 19:07:20 +00:00
</details>
<details>
<summary>Android</summary>
To install `zoxide`, use a package manager:
2020-11-06 19:54:14 +00:00
2021-03-14 15:19:51 +00:00
| Repository | Instructions |
| ---------- | -------------------- |
| [Termux] | `pkg install zoxide` |
2020-11-06 19:54:14 +00:00
2021-07-21 19:07:20 +00:00
</details>
2021-08-05 08:52:12 +00:00
### *Step 2: Add `zoxide` to your shell*
To start using `zoxide`, add it to your shell.
2021-07-21 19:07:20 +00:00
<details>
<summary><code>bash</code></summary>
2020-03-08 19:12:09 +00:00
2021-04-27 12:07:38 +00:00
Add this to your configuration (usually `~/.bashrc`):
2020-03-08 19:12:09 +00:00
```sh
eval "$(zoxide init bash)"
2020-03-08 19:12:09 +00:00
```
2021-07-21 19:07:20 +00:00
</details>
<details>
<summary><code>elvish</code></summary>
2021-04-08 18:35:42 +00:00
2021-04-27 12:07:38 +00:00
Add this to your configuration (usually `~/.elvish/rc.elv`):
2021-04-08 18:35:42 +00:00
```sh
2021-05-26 21:04:01 +00:00
eval (zoxide init elvish | slurp)
2021-04-08 18:35:42 +00:00
```
2021-08-31 10:59:57 +00:00
Note: zoxide only supports elvish v0.16.0 and above.
2021-08-23 20:30:34 +00:00
2021-07-21 19:07:20 +00:00
</details>
<details>
<summary><code>fish</code></summary>
2020-03-08 19:05:37 +00:00
2021-04-27 12:07:38 +00:00
Add this to your configuration (usually `~/.config/fish/config.fish`):
2020-03-08 19:05:37 +00:00
2021-03-31 16:45:43 +00:00
```fish
zoxide init fish | source
2020-03-08 16:15:06 +00:00
```
2021-07-21 19:07:20 +00:00
</details>
<details>
2021-08-23 20:30:34 +00:00
<summary><code>nushell</code></summary>
2021-03-31 16:45:43 +00:00
2021-08-05 08:52:12 +00:00
Add this to your configuration (find it by running `config path` in Nushell):
2021-03-31 16:45:43 +00:00
2021-04-27 12:07:38 +00:00
```toml
startup = ["zoxide init nushell --hook prompt | save ~/.zoxide.nu", "source ~/.zoxide.nu"]
```
2021-09-17 20:13:59 +00:00
Note: zoxide only supports Nushell v0.37.0 and above.
2021-03-31 16:45:43 +00:00
2021-07-21 19:07:20 +00:00
</details>
<details>
<summary><code>powershell</code></summary>
2020-05-06 06:03:06 +00:00
2021-08-05 08:52:12 +00:00
Add this to your configuration (find it by running `echo $profile` in
PowerShell):
2020-05-06 06:03:06 +00:00
```powershell
Invoke-Expression (& {
$hook = if ($PSVersionTable.PSVersion.Major -lt 6) { 'prompt' } else { 'pwd' }
(zoxide init --hook $hook powershell) -join "`n"
})
```
2021-07-21 19:07:20 +00:00
</details>
<details>
<summary><code>xonsh</code></summary>
2020-10-30 18:52:09 +00:00
2021-04-27 12:07:38 +00:00
Add this to your configuration (usually `~/.xonshrc`):
2020-10-30 18:52:09 +00:00
2021-03-31 16:45:43 +00:00
```python
2020-10-30 18:52:09 +00:00
execx($(zoxide init xonsh), 'exec', __xonsh__.ctx, filename='zoxide')
```
2021-07-21 19:07:20 +00:00
</details>
<details>
<summary><code>zsh</code></summary>
2020-05-24 21:25:00 +00:00
2021-04-27 12:07:38 +00:00
Add this to your configuration (usually `~/.zshrc`):
2020-05-24 21:25:00 +00:00
```sh
eval "$(zoxide init zsh)"
```
2021-07-21 19:07:20 +00:00
</details>
<details>
<summary>any POSIX shell</summary>
2020-10-31 08:15:29 +00:00
2021-04-27 12:07:38 +00:00
Add this to your configuration:
2020-10-31 08:15:29 +00:00
```sh
eval "$(zoxide init posix --hook prompt)"
```
2021-07-21 19:07:20 +00:00
</details>
2021-08-05 08:52:12 +00:00
### *Step 3: Install `fzf` (optional)*
[`fzf`][fzf] is a command-line fuzzy finder, used by `zoxide` for interactive
selection. It can be installed from [here][fzf-installation].
### *Step 4: Import your data (optional)*
If you currently use any of the following utilities, you may want to import
your data into `zoxide`:
<details>
<summary><code>autojump</code></summary>
```sh
zoxide import --from autojump path/to/db
```
</details>
<details>
<summary><code>z</code>, <code>z.lua</code>, or <code>zsh-z</code></summary>
```sh
zoxide import --from z path/to/db
```
</details>
2020-03-07 21:04:47 +00:00
## Configuration
2021-07-21 19:07:20 +00:00
### Flags
When calling `zoxide init`, the following flags are available:
2020-03-15 18:36:06 +00:00
2021-07-21 19:07:20 +00:00
- `--cmd`
- Changes the prefix of predefined aliases (`z`, `zi`).
2021-03-14 15:19:51 +00:00
- e.g. `--cmd j` would change the aliases to `j` and `ji` respectively.
2021-07-21 19:07:20 +00:00
- `--hook <HOOK>`
- Changes how often `zoxide` increments a directory's score:
| Hook | Description |
| -------- | --------------------------------- |
| `none` | Never |
| `prompt` | At every shell prompt |
| `pwd` | Whenever the directory is changed |
- `--no-aliases`
- Don't define extra aliases (`z`, `zi`).
2021-04-11 20:26:48 +00:00
- These functions will still be available in your shell as `__zoxide_z` and
2021-07-21 19:07:20 +00:00
`__zoxide_zi`, should you choose to redefine them.
2020-03-15 18:36:06 +00:00
2020-03-07 21:04:47 +00:00
### Environment variables
Environment variables<sup>[?][wiki-env]</sup> can be used for configuration.
They must be set before `zoxide init` is called.
2021-03-31 16:45:43 +00:00
2021-03-14 15:19:51 +00:00
- `_ZO_DATA_DIR`
- Specifies the directory in which the database is stored.
2021-03-14 15:19:51 +00:00
- The default value varies across OSes:
| OS | Path | Example |
| ----------- | ---------------------------------------- | ------------------------------------------ |
| Linux / BSD | `$XDG_DATA_HOME` or `$HOME/.local/share` | `/home/alice/.local/share` |
| macOS | `$HOME/Library/Application Support` | `/Users/Alice/Library/Application Support` |
| Windows | `{FOLDERID_RoamingAppData}` | `C:\Users\Alice\AppData\Roaming` |
- `_ZO_ECHO`
2021-04-11 20:26:48 +00:00
- When set to `1`, `z` will print the matched directory before navigating to
it.
2021-03-14 15:19:51 +00:00
- `_ZO_EXCLUDE_DIRS`
- Excludes the specified directories from the database.
2021-04-11 20:26:48 +00:00
- This is provided as a list of [globs][glob], separated by OS-specific
characters:
2021-03-14 15:19:51 +00:00
| OS | Separator | Example |
| ------------------- | --------- | ----------------------- |
| Linux / macOS / BSD | `:` | `$HOME:$HOME/private/*` |
| Windows | `;` | `$HOME;$HOME/private/*` |
- By default, this is set to `"$HOME"`.
2021-03-14 15:19:51 +00:00
- `_ZO_FZF_OPTS`
- Custom options to pass to [`fzf`][fzf]. See [`man fzf`][fzf-man] for the list
of options.
2021-03-14 15:19:51 +00:00
- `_ZO_MAXAGE`
2021-04-11 20:26:48 +00:00
- Configures the [aging algorithm][algorithm-aging], which limits the maximum
number of entries in the database.
2021-03-14 15:19:51 +00:00
- By default, this is set to `10000`.
- `_ZO_RESOLVE_SYMLINKS`
2021-04-11 20:26:48 +00:00
- When set to `1`, `z` will resolve symlinks before adding directories to the
database.
2021-03-14 15:19:51 +00:00
## Third-party integrations
| Application | Description | Plugin |
| ------------------ | --------------------------------------- | -------------------------- |
| [emacs] | Text editor | [zoxide.el] |
| [nnn] | File manager | [nnn-autojump] |
| [ranger] | File manager | [ranger-zoxide] |
| [telescope.nvim] | Fuzzy finder for Neovim | [telescope-zoxide] |
| [vim] | Text editor | [zoxide.vim] |
| [xxh] | Transports shell configuration over SSH | [xxh-plugin-prerun-zoxide] |
| [zsh-autocomplete] | Realtime completions for zsh | Supported by default |
2021-04-11 20:26:48 +00:00
[algorithm-aging]: https://github.com/ajeetdsouza/zoxide/wiki/Algorithm#aging
[algorithm-matching]: https://github.com/ajeetdsouza/zoxide/wiki/Algorithm#matching
2021-03-14 15:19:51 +00:00
[alpine linux packages]: https://pkgs.alpinelinux.org/packages?name=zoxide
[arch linux community]: https://archlinux.org/packages/community/x86_64/zoxide/
2021-09-06 20:54:11 +00:00
[builtwithnix-badge]: https://img.shields.io/badge/builtwith-nix-7d81f7
[builtwithnix]: https://builtwithnix.org/
[chocolatey]: https://community.chocolatey.org/packages/zoxide
[conda-forge]: https://anaconda.org/conda-forge/zoxide
2021-03-14 15:19:51 +00:00
[copr]: https://copr.fedorainfracloud.org/coprs/atim/zoxide/
2021-09-06 20:54:11 +00:00
[crates.io-badge]: https://img.shields.io/crates/v/zoxide
2021-08-05 08:52:12 +00:00
[crates.io]: https://crates.io/crates/zoxide
2021-08-30 08:19:18 +00:00
[debian packages]: https://packages.debian.org/stable/admin/zoxide
2021-04-28 19:53:43 +00:00
[devuan packages]: https://pkginfo.devuan.org/cgi-bin/package-query.html?c=package&q=zoxide
2021-09-06 20:54:11 +00:00
[downloads-badge]: https://img.shields.io/github/downloads/ajeetdsouza/zoxide/total
2021-03-14 15:19:51 +00:00
[dports]: https://github.com/DragonFlyBSD/DPorts/tree/master/sysutils/zoxide
2021-07-29 06:59:41 +00:00
[emacs]: https://www.gnu.org/software/emacs/
2021-03-14 15:19:51 +00:00
[fedora packages]: https://src.fedoraproject.org/rpms/rust-zoxide
2021-04-11 20:26:48 +00:00
[freshports]: https://www.freshports.org/sysutils/zoxide/
[fzf-installation]: https://github.com/junegunn/fzf#installation
[fzf-man]: https://manpages.ubuntu.com/manpages/en/man1/fzf.1.html
2021-04-11 20:26:48 +00:00
[fzf]: https://github.com/junegunn/fzf
[glob]: https://man7.org/linux/man-pages/man7/glob.7.html
2021-07-21 19:07:20 +00:00
[guru overlay]: https://github.com/gentoo-mirror/guru
2021-03-14 15:19:51 +00:00
[homebrew]: https://formulae.brew.sh/formula/zoxide
2021-07-21 19:07:20 +00:00
[issues]: https://github.com/ajeetdsouza/zoxide/issues/new
2021-03-14 15:19:51 +00:00
[linuxbrew]: https://formulae.brew.sh/formula-linux/zoxide
[macports]: https://ports.macports.org/port/zoxide/summary
2021-06-06 18:05:59 +00:00
[neovim]: https://github.com/neovim/neovim
2021-04-11 20:26:48 +00:00
[nixpkgs]: https://github.com/NixOS/nixpkgs/blob/master/pkgs/tools/misc/zoxide/default.nix
[nnn-autojump]: https://github.com/jarun/nnn/blob/master/plugins/autojump
[nnn]: https://github.com/jarun/nnn
2020-11-27 09:50:06 +00:00
[pkgsrc]: https://pkgsrc.se/sysutils/zoxide
2021-06-06 18:05:59 +00:00
[ranger-zoxide]: https://github.com/jchook/ranger-zoxide
[ranger]: https://github.com/ranger/ranger
[releases]: https://github.com/ajeetdsouza/zoxide/releases
2021-03-14 15:19:51 +00:00
[scoop]: https://github.com/ScoopInstaller/Main/tree/master/bucket/zoxide.json
2021-05-18 02:28:16 +00:00
[telescope-zoxide]: https://github.com/jvgrootveld/telescope-zoxide
[telescope.nvim]: https://github.com/nvim-telescope/telescope.nvim
2021-03-14 15:19:51 +00:00
[termux]: https://github.com/termux/termux-packages/tree/master/packages/zoxide
2021-05-15 04:13:55 +00:00
[tutorial]: contrib/tutorial.webp
2021-04-28 19:53:43 +00:00
[ubuntu packages]: https://packages.ubuntu.com/hirsute/zoxide
2021-06-06 18:05:59 +00:00
[vim]: https://github.com/vim/vim
2021-03-14 15:19:51 +00:00
[void linux packages]: https://github.com/void-linux/void-packages/tree/master/srcpkgs/zoxide
[wiki-env]: https://github.com/ajeetdsouza/zoxide/wiki/HOWTO:-set-environment-variables "HOWTO: set environment variables"
[xxh-plugin-prerun-zoxide]: https://github.com/xxh/xxh-plugin-prerun-zoxide
2021-04-11 20:26:48 +00:00
[xxh]: https://github.com/xxh/xxh
[zoxide.el]: https://gitlab.com/Vonfry/zoxide.el
[zoxide.vim]: https://github.com/nanotee/zoxide.vim
2021-05-18 02:28:16 +00:00
[zsh-autocomplete]: https://github.com/marlonrichert/zsh-autocomplete