blob: 9c5601b82b31b6e13731889621336144bd418164 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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
}
|