mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-10-16 12:21:18 +02:00
85 lines
2.3 KiB
Text
85 lines
2.3 KiB
Text
#autoload
|
|
|
|
# This completer function is intended to be used as the first completer
|
|
# function and allows one to say more explicitly when and how the word
|
|
# from the line should be expanded than expand-or-complete.
|
|
# This function will allow other completer functions to be called if
|
|
# the expansions done produce no result or do not change the original
|
|
# word from the line.
|
|
|
|
local exp word="$PREFIX$SUFFIX" sort expr expl curcontext="${curcontext}"
|
|
|
|
[[ "$curcontext" != :expand* ]] && curcontext="${curcontext}:expand"
|
|
|
|
# First, see if we should insert all *completions*.
|
|
|
|
if zstyle -s ":completion${curcontext}:" completions expr &&
|
|
[[ "${(e):-\$[$expr]}" -eq 1 ]]; then
|
|
compstate[insert]=all
|
|
return 1
|
|
fi
|
|
|
|
# Do this only for the first global matcher.
|
|
|
|
[[ "$compstate[matcher]" -le 1 ]] || return 1
|
|
|
|
# In exp we will collect the expansion.
|
|
|
|
exp=("$word")
|
|
|
|
# First try substitution. That weird thing spanning multiple lines
|
|
# changes quoted spaces, tabs, and newlines into spaces.
|
|
|
|
zstyle -s ":completion${curcontext}:" substitute expr &&
|
|
[[ "${(e):-\$[$expr]}" -eq 1 ]] &&
|
|
exp=( "${(e)exp//\\[
|
|
]/ }" )
|
|
|
|
# If the array is empty, store the original string again.
|
|
|
|
[[ -z "$exp" ]] && exp=("$word")
|
|
|
|
# Now try globbing.
|
|
|
|
zstyle -s ":completion${curcontext}:" glob expr &&
|
|
[[ "${(e):-\$[$expr]}" -eq 1 ]] &&
|
|
exp=( ${~exp}(N) )
|
|
|
|
# If we don't have any expansions or only one and that is the same
|
|
# as the original string, we let other completers run.
|
|
|
|
[[ $#exp -eq 0 ||
|
|
( $#exp -eq 1 && "$exp[1]" = "$word"(|\(N\)) ) ]] && return 1
|
|
|
|
# Now add as matches whatever the user requested.
|
|
|
|
zstyle -s ":completion${curcontext}:" sort sort
|
|
|
|
[[ "$sort" = (yes|true|1|on) ]] && exp=( "${(@o)exp}" )
|
|
|
|
if [[ -z "$compstate[insert]" ]] ;then
|
|
_description all-expansions expl 'all expansions' "o:$word"
|
|
|
|
compadd "$expl[@]" -UQ - "$exp"
|
|
else
|
|
_tags all-expansions expansions original
|
|
|
|
|
|
_requested all-expansions expl 'all expansions' "o:$word" &&
|
|
compadd "$expl[@]" -UQ "$exp"
|
|
|
|
if _requested expansions; then
|
|
if [[ "$sort" = menu ]]; then
|
|
_description expansions expl expansions "o:$word"
|
|
else
|
|
_description -V expansions expl expansions "o:$word"
|
|
fi
|
|
compadd "$expl[@]" -UQ - "$exp[@]"
|
|
fi
|
|
|
|
_requested original expl original && compadd "$expl[@]" -UQ - "$word"
|
|
|
|
compstate[insert]=menu
|
|
fi
|
|
|
|
return 0
|