LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   LinuxQuestions.org Member Success Stories (https://www.linuxquestions.org/questions/linuxquestions-org-member-success-stories-23/)
-   -   Simplest ZSH AutoJump (https://www.linuxquestions.org/questions/linuxquestions-org-member-success-stories-23/simplest-zsh-autojump-4175698667/)

dugan 08-03-2021 12:01 PM

Simplest ZSH AutoJump
 
This is the simplest (and IMHO correct) way to set up an equivalent of autojump in ZSH:

Code:

autoload -Uz chpwd_recent_dirs cdr add-zsh-hook
add-zsh-hook chpwd chpwd_recent_dirs
zstyle ':completion:*:*:cdr:*:*' menu selection
zstyle ':chpwd:*' recent-dirs-default yes
zstyle ':completion:*' recent-dirs-insert always
zstyle ':completion:*:*:cdr:*:*' list-suffixeszstyle
zstyle ':completion:*:*:cdr:*:*' expand prefix suffix
alias j=cdr

See the zshcontrib manpage for the explanation.

The list-suffiszstyle and "expand prefix suffix" options are to get TAB-completion to work if you just enter a substring of a directory in your history and press TAB. It's from here: Moving to zsh, part 5: Completions

Or, if you'd prefer a more FISH-like experience where the CD command is augmented with history completion and everything can complete from the middle of a string:

Code:

autoload -Uz chpwd_recent_dirs cdr add-zsh-hook
add-zsh-hook chpwd chpwd_recent_dirs
zstyle ':completion:*:*:cdr:*:*' menu selection
zstyle ':chpwd:*' recent-dirs-default yes
zstyle ':completion:*' recent-dirs-insert both

zstyle ':completion:*' list-suffixes
zstyle ':completion:*' expand prefix suffix

alias cd=cdr

My ZSH setup, btw, is Oh My ZSH with the fzf, history-substring-search, zsh-autosuggestions and zsh-syntax-highlighting plugins. It's pretty typical.


All times are GMT -5. The time now is 01:53 AM.