zoxide/README.md

417 lines
16 KiB
Markdown
Raw Normal View History

2021-09-17 19:59:46 +00:00
<!-- markdownlint-configure-file {
"MD013": {
"code_blocks": false,
"tables": false
},
2021-10-28 06:53:14 +00:00
"MD033": false,
"MD041": false
2021-09-17 19:59:46 +00:00
} -->
2021-07-21 19:07:20 +00:00
2021-10-28 06:53:14 +00:00
<div align="center">
2021-10-28 06:38:57 +00:00
# zoxide
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-10-28 06:53:14 +00:00
zoxide is a **smarter cd command**, inspired by z and autojump.
2020-03-07 21:04:47 +00:00
2021-10-28 06:53:14 +00:00
It remembers which directories you use most frequently, so you can "jump" to
them in just a few keystrokes.<br />
zoxide works on all major shells.
[Getting started](#getting-started) •
[Installation](#installation) •
[Configuration](#configuration) •
[Integrations](#third-party-integrations)
</div>
2020-05-29 23:38:30 +00:00
2021-10-28 06:53:14 +00:00
## Getting started
![Tutorial][tutorial]
2020-03-07 21:04:47 +00:00
```sh
2021-12-05 08:58:31 +00:00
z foo # cd into highest ranked directory matching foo
z foo bar # cd into highest ranked directory matching foo and bar
2022-01-20 21:44:28 +00:00
z foo / # cd into a subdirectory starting with foo
2020-03-07 21:04:47 +00:00
2021-12-05 08:58:31 +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-12-05 08:58:31 +00:00
zi foo # cd with interactive selection (using fzf)
2022-02-25 04:19:45 +00:00
z foo<SPACE><TAB> # show interactive completions (zoxide v0.8.0+, bash 4.4+/fish/zsh only)
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].
2021-10-28 06:53:14 +00:00
## Installation
2020-03-07 21:04:47 +00:00
2021-10-28 06:38:57 +00:00
### *Step 1: Install zoxide*
2020-03-07 21:04:47 +00:00
2021-10-28 06:38:57 +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>
2021-11-10 05:07:47 +00:00
To install zoxide, run this command in your terminal:
```sh
curl -sS https://webinstall.dev/zoxide | bash
```
Alternatively, you can use a package manager:
2021-07-21 19:07:20 +00:00
| Distribution | Repository | Instructions |
| ------------------ | ----------------------- | ---------------------------------------------------------------------------------------------- |
2021-10-20 18:31:06 +00:00
| ***Any*** | **[crates.io]** | `cargo install zoxide --locked` |
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-11-30 21:48:33 +00:00
| Raspbian 11+ | [Raspbian Packages] | `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-10-28 06:38:57 +00:00
To install zoxide, use a package manager:
2020-03-07 21:04:47 +00:00
| Repository | Instructions |
| --------------- | ------------------------------------- |
2021-10-20 18:31:06 +00:00
| **[crates.io]** | `cargo install zoxide --locked` |
| [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>
2021-10-28 06:38:57 +00:00
To install zoxide, run this command in your command prompt:
2021-07-21 19:07:20 +00:00
```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-10-20 18:31:06 +00:00
| **[crates.io]** | `cargo install zoxide --locked` |
| [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>
2021-10-28 06:38:57 +00:00
To install zoxide, use a package manager:
2020-03-07 21:04:47 +00:00
2021-10-20 18:31:06 +00:00
| Distribution | Repository | Instructions |
| ------------- | --------------- | ------------------------------- |
| ***Any*** | **[crates.io]** | `cargo install zoxide --locked` |
| 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>
2021-10-28 06:38:57 +00:00
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-10-28 06:38:57 +00:00
### *Step 2: Add zoxide to your shell*
2021-10-28 06:38:57 +00:00
To start using zoxide, add it to your shell.
2021-07-21 19:07:20 +00:00
<details>
2021-10-28 06:53:14 +00:00
<summary>Bash</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>
2021-10-28 06:53:14 +00:00
<summary>Elvish</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>
2021-10-28 06:53:14 +00:00
<summary>Fish</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-10-28 06:53:14 +00:00
<summary>Nushell</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>
2021-10-28 06:53:14 +00:00
<summary>PowerShell</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
2021-12-14 19:43:45 +00:00
# For zoxide v0.8.0+
Invoke-Expression (& {
$hook = if ($PSVersionTable.PSVersion.Major -lt 6) { 'prompt' } else { 'pwd' }
(zoxide init --hook $hook powershell | Out-String)
})
# For older versions of zoxide
2020-05-06 06:03:06 +00:00
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>
2021-10-28 06:53:14 +00:00
<summary>Xonsh</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>
2021-10-28 06:53:14 +00:00
<summary>Zsh</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-12-24 12:19:36 +00:00
For completions to work, the above line must be added _after_ `compinit` is
2021-12-28 18:10:10 +00:00
called. You may have to rebuild your cache by running `rm ~/.zcompdump*; compinit`.
2021-12-05 08:58:31 +00:00
2021-07-21 19:07:20 +00:00
</details>
<details>
2021-10-28 06:53:14 +00:00
<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-10-28 06:38:57 +00:00
### *Step 3: Install fzf (optional)*
2021-08-05 08:52:12 +00:00
2021-10-28 06:38:57 +00:00
[fzf] is a command-line fuzzy finder, used by zoxide for interactive
2022-02-01 22:25:21 +00:00
selection. It can be installed from [here][fzf-installation]. zoxide supports
fzf v0.21.0+.
2021-08-05 08:52:12 +00:00
### *Step 4: Import your data (optional)*
If you currently use any of the following utilities, you may want to import
2021-10-28 06:38:57 +00:00
your data into zoxide:
2021-08-05 08:52:12 +00:00
<details>
2021-10-28 06:38:57 +00:00
<summary>autojump</summary>
2021-08-05 08:52:12 +00:00
```sh
zoxide import --from autojump path/to/db
```
</details>
<details>
2021-10-28 06:38:57 +00:00
<summary>z, z.lua, or zsh-z</summary>
2021-08-05 08:52:12 +00:00
```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-10-28 06:38:57 +00:00
- `--cmd j` would change the aliases to (`j`, `ji`).
- `--cmd cd` would replace the `cd` command (doesn't work on Nushell / POSIX shells).
2021-07-21 19:07:20 +00:00
- `--hook <HOOK>`
2021-10-28 06:38:57 +00:00
- Changes how often zoxide increments a directory's score:
2021-07-21 19:07:20 +00:00
| Hook | Description |
| -------- | --------------------------------- |
| `none` | Never |
| `prompt` | At every shell prompt |
| `pwd` | Whenever the directory is changed |
- `--no-aliases`
2021-10-28 06:38:57 +00:00
- Don't define 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 | `%LOCALAPPDATA%` | `C:\Users\Alice\AppData\Local` |
2021-03-14 15:19:51 +00:00
- `_ZO_ECHO`
2021-10-28 06:38:57 +00:00
- When set to 1, `z` will print the matched directory before navigating to
2021-04-11 20:26:48 +00:00
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`
2021-10-28 06:38:57 +00:00
- Custom options to pass to [fzf] during interactive selection. 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-10-28 06:38:57 +00:00
- By default, this is set to 10000.
2021-03-14 15:19:51 +00:00
- `_ZO_RESOLVE_SYMLINKS`
2021-10-28 06:38:57 +00:00
- When set to 1, `z` will resolve symlinks before adding directories to the
2021-04-11 20:26:48 +00:00
database.
2021-03-14 15:19:51 +00:00
## Third-party integrations
2022-03-03 23:36:32 +00:00
| Application | Description | Plugin |
| ------------------ | -------------------------------------------- | -------------------------- |
| [clink] | Improved cmd.exe for Windows | [clink-zoxide] |
| [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] |
| [xplr] | File manager | [zoxide.xplr] |
| [xxh] | Transports shell configuration over SSH | [xxh-plugin-prerun-zoxide] |
| [zabb] | Finds the shortest possible query for a path | Natively supported |
| [zsh-autocomplete] | Realtime completions for zsh | Natively supported |
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-12-05 08:58:31 +00:00
[builtwithnix-badge]: https://img.shields.io/badge/builtwith-nix-7d81f7?style=flat-square
2021-09-06 20:54:11 +00:00
[builtwithnix]: https://builtwithnix.org/
[chocolatey]: https://community.chocolatey.org/packages/zoxide
2022-03-03 23:36:32 +00:00
[clink-zoxide]: https://github.com/shunsambongi/clink-zoxide
[clink]: https://github.com/mridgers/clink
[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-12-05 08:58:31 +00:00
[crates.io-badge]: https://img.shields.io/crates/v/zoxide?style=flat-square
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-12-05 08:58:31 +00:00
[downloads-badge]: https://img.shields.io/github/downloads/ajeetdsouza/zoxide/total?style=flat-square
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
2021-11-30 21:48:33 +00:00
[raspbian packages]: https://archive.raspbian.org/raspbian/pool/main/r/rust-zoxide/
2021-06-06 18:05:59 +00:00
[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"
2021-10-05 10:26:04 +00:00
[xplr]: https://github.com/sayanarijit/xplr
[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
2022-03-03 23:36:32 +00:00
[zabb]: https://github.com/Mellbourn/zabb
[zoxide.el]: https://gitlab.com/Vonfry/zoxide.el
[zoxide.vim]: https://github.com/nanotee/zoxide.vim
2021-10-05 10:26:04 +00:00
[zoxide.xplr]: https://github.com/sayanarijit/zoxide.xplr
2021-05-18 02:28:16 +00:00
[zsh-autocomplete]: https://github.com/marlonrichert/zsh-autocomplete