Zoxide
Zoxide is a smarter cd command, inspired by z and autojump. It remembers which directories you use most frequently, so you can "jump" to them in just a few keystrokes. Zoxide works on all major shells.
What is Zoxide?
- Smart
cdreplacement that remembers your most-used directories - Works like
autojump/z.shbut faster and simpler - Learns as you use it - no manual bookmarking needed
Installation
For Windows (PowerShell):
winget install zoxideBasic Setup
Add this to the end of your shell config file (usually ~/.bashrc or ~/.zshrc):
eval "$(zoxide init zsh)" # For zshFor PowerShell, add this to the end of your config file:
Invoke-Expression (& { (zoxide init powershell | Out-String) })Essential Commands
Same as how you use the cd command:
z ..: 返回上一级z: 返回家目录z -: 返回上一次进入的目录
See zoxide --help
Go to the highest-ranked directory that contains "foo" in the name:
zoxide query fooGo to the highest-ranked directory that contains "foo" and then "bar":
zoxide query foo barStart an interactive directory search (requires
fzf):zoxide query --interactiveAdd a directory or increment its rank:
zoxide add path/to/directoryRemove a directory from zoxide's database interactively:
zoxide remove path/to/directory --interactiveGenerate shell configuration for command aliases (z, za, zi, zq, zr):
zoxide init bash|fish|zshCommand Description Example z <query>Jump to directory z docu→ goes to~/DocumentsziInteractive search zi→ fuzzy find directoriesOther commands such as
za,zq,zrdo not work.zsh: command not found: za
Database Location
| OS | Path | Example |
|---|---|---|
| Windows | %LOCALAPPDATA% | C:\Users\Alice\AppData\Local\zoxide\db.zo |
改造命令
When calling zoxide init, the following flags are available:
--cmd- Changes the prefix of the
zandzicommands. --cmd jwould change the commands to (j,ji).--cmd cdwould replace thecdcommand.
- Changes the prefix of the
如果习惯了使用 cd 命令,可以使用以下改造方法,显式仍然使用 cd 命令,但是背地却是调用了 z 命令。
Add this to the end of your shell config file (usually ~/.bashrc or ~/.zshrc):
eval "$(zoxide init --cmd cd zsh)" # For zshFor PowerShell, add this to the end of your config file:
Invoke-Expression (& { (zoxide init --cmd cd powershell | Out-String) })