diff options
Diffstat (limited to 'dot-oh-my-zsh/custom/plugins/zsh-autocomplete/scripts/.autocomplete.recent-dirs')
| -rw-r--r-- | dot-oh-my-zsh/custom/plugins/zsh-autocomplete/scripts/.autocomplete.recent-dirs | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/dot-oh-my-zsh/custom/plugins/zsh-autocomplete/scripts/.autocomplete.recent-dirs b/dot-oh-my-zsh/custom/plugins/zsh-autocomplete/scripts/.autocomplete.recent-dirs new file mode 100644 index 00000000..9c5601b8 --- /dev/null +++ b/dot-oh-my-zsh/custom/plugins/zsh-autocomplete/scripts/.autocomplete.recent-dirs @@ -0,0 +1,92 @@ +#!/bin/zsh +zmodload -Fa zsh/files b:zf_mv b:zf_mkdir +zmodload -F zsh/parameter p:commands p:dirstack p:functions + +.autocomplete.recent-dirs.precmd() { + # NOTE: Cannot set localopts, because of `cdr`, below. + + if [[ -v precmd_functions && $precmd_functions[(I)_zshz_precmd] != 0 ]] && + builtin zstyle -T ':autocomplete:recent-dirs' backend 'zsh-z'; then + _autocomplete.recent_directories() { + reply=( ${(f)"$( zshz --complete -l $1 2> /dev/null )"} ) + } + + elif [[ -v chpwd_functions && $chpwd_functions[(I)__zoxide_hook] != 0 ]] && + builtin zstyle -T ':autocomplete:recent-dirs' backend'zoxide'; then + _autocomplete.recent_directories() { + reply=( ${(f)"$( zoxide query --list $1 2> /dev/null )"} ) + } + + elif [[ -v chpwd_functions && $chpwd_functions[(I)_zlua_precmd] != 0 ]] && + builtin zstyle -T ':autocomplete:recent-dirs' backend 'z.lua'; then + _autocomplete.recent_directories() { + reply=( ${${(f)"$( _zlua --complete $1 2> /dev/null )"}##<->[[:space:]]##} ) + } + + elif [[ -v precmd_functions && $precmd_functions[(I)_z_precmd] != 0 ]] && + builtin zstyle -T ':autocomplete:recent-dirs' backend 'z.sh'; then + _autocomplete.recent_directories() { + reply=( ${${(fOa)"$( _z -l $1 2>&1 )"}##(common:|<->)[[:space:]]##} ) + } + + elif [[ -v chpwd_functions && $chpwd_functions[(I)autojump_chpwd] != 0 ]] && + builtin zstyle -T ':autocomplete:recent-dirs' backend 'autojump'; then + _autocomplete.recent_directories() { + reply=( ${${(f)"$( autojump --complete $1 2> /dev/null )"}##${1}__<->__} ) + } + + elif [[ -v preexec_functions && $preexec_functions[(I)_fasd_preexec] != 0 ]] && + builtin zstyle -T ':autocomplete:recent-dirs' backend 'fasd'; then + _autocomplete.recent_directories() { + reply=( ${(f)"$( fasd -dlR $1 2> /dev/null )"} ) + } + + elif builtin autoload -RUz chpwd_recent_filehandler && + builtin zstyle -T ':autocomplete:recent-dirs' backend 'cdr'; then + setopt autopushd pushdignoredups + + if ! builtin zstyle -s :chpwd: recent-dirs-file _; then + local -P old=${ZDOTDIR:-$HOME}/.chpwd-recent-dirs + local -P new=${XDG_DATA_HOME:-$HOME/.local/share}/zsh/chpwd-recent-dirs + builtin zstyle ':chpwd:*' recent-dirs-file $new + [[ -e $old && ! -e $new ]] && + zf_mv "$old" "$new" + fi + builtin zstyle -s :chpwd: recent-dirs-max _ || + builtin zstyle ':chpwd:*' recent-dirs-max 0 + + if ! (( $#dirstack[@] )); then + local -aU reply=() + chpwd_recent_filehandler + dirstack=( ${^reply[@]:#$PWD}(N-/) ) + fi + + _autocomplete.recent_directories.save() { + chpwd_recent_filehandler $PWD $dirstack[@] + } + add-zsh-hook chpwd _autocomplete.recent_directories.save + + _autocomplete.recent_directories() { + reply=( ${^dirstack[@]:#$PWD(|/[^/]#)}(N) ) + + local -P ancestor=$PWD:h + while [[ $ancestor != / ]]; do + reply=( ${reply[@]:#$ancestor} ) + ancestor=$ancestor:h + done + + local exact=$reply[(r)*/$PREFIX$SUFFIX] + [[ -n $exact ]] && + reply=( $exact ${reply[@]:#$exact} ) + + (( $#reply[@] )) + } + fi + + if [[ -v preexec_functions && $preexec_functions[(I)_fasd_preexec] != 0 ]] && + builtin zstyle -T ':autocomplete:' recent-files 'fasd'; then + _autocomplete.recent_files() { + reply=( $( fasd -flR $1 2> /dev/null ) ) + } + fi +} |
