move to new repo

This commit is contained in:
tumillanino
2026-03-24 20:17:22 +11:00
parent 083b57c87b
commit 35bcba335a
1910 changed files with 161640 additions and 41 deletions

View File

@@ -0,0 +1,6 @@
#compdef -command-
local -P ret=1
_autocd "$@" &&
ret=0
return ret

View File

@@ -0,0 +1,10 @@
#autoload
local -Pi len=$(( ${@[(i)(-|--)]} - 1 ))
(( len < $# )) &&
return len
len=${@[(I)-*]}
[[ $@[len] == -*[PSpsiIdJVXxrRWFMOAD] ]] &&
(( len++ ))
return len

View File

@@ -0,0 +1,164 @@
#autoload
_autocomplete__history_lines() {
setopt localoptions multibyte
# Don't run more than once.
(( _matcher_num > 1 )) &&
return 1
local -P lbuffer='' rbuffer=''
(( CURRENT > 1 )) &&
lbuffer="${(j.[[:blank:]]##.)${(@b)words[1,CURRENT-1]}}[[:blank:]]##"
(( CURRENT < $#words[@] )) &&
rbuffer="[[:blank:]]##${(j.[[:blank:]]##.)${(@b)words[CURRENT+1,-1]}}"
lbuffer="$lbuffer${(b)QIPREFIX}"
rbuffer="${(b)QISUFFIX}$rbuffer"
local -P query=''
if [[ -n $words[CURRENT] ]]; then
local -Pa includes=( "${(@s..b)^words[CURRENT]}" )
local -Pa excludes=( "(|[^${(@s..b)^words[CURRENT]}\n;]#)" )
local -Pa tokens=( ${(@)excludes:^includes} )
query="((#l)$tokens[2]${(j..)tokens[3,-1]})"
local -P no_delim='[^\n;]#' pre='' post=''
if [[ -z $lbuffer ]]; then
pre='*'
else
pre=$no_delim
fi
if [[ -z $rbuffer ]]; then
post='*'
else
post=$no_delim
fi
query="(|$pre)$query$post"
else
query='()*'
fi
[[ $curcontext == *-incremental-* ]]
local -Pi is_incremental=$(( ! ? ))
# Non-incremental search potentially adds a lot of completions, which can be quite slow.
(( is_incremental )) ||
zle -R 'Loading...'
# Using fc is way faster than using $history.
local -P output="$( fc -lrm "$lbuffer$query$rbuffer" -1 1 2> /dev/null )"
# No results
[[ -z $output ]] &&
return 1
local -aU displays=( "${(f)output}" )
local -P numpat='[[:blank:]]#(<->)[*[:blank:]][[:blank:]]'
local -P groups="${(l:$(( 2 * $#words[CURRENT] ))::=0:):-}"
_comp_colors=(
"=(#b)${numpat}${lbuffer}(${query})${rbuffer}${rbuffer:+[[:blank:]]#}=2=2=0=0=30;103$groups"
"=(#b)${numpat}${lbuffer}(${query})*=2=2=0=30;103$groups"
"=(#b)${numpat}${lbuffer}(*)=2=2=0"
"=(#b)${numpat}*=0=2"
${(M)_comp_colors:#ma=*}
)
local -Pi excess= index= max= list_lines=
if (( is_incremental )); then
.autocomplete:async:list-choices:max-lines
(( list_lines = _autocomplete__max_lines ))
(( max = 16 * list_lines )) # Buffer for bubbling up more relevant results.
else
zstyle -s ":autocomplete:${curcontext}:" list-lines list_lines ||
(( list_lines = $LINES / 2 ))
(( max = $list_lines ))
fi
if [[ -o histfindnodups ]]; then
local -PaU uniques=()
local -Pa lines=()
local -Pi size=0
for index in {$#displays[@]..1}; do
uniques+=( ${displays[index]##$~numpat} )
(( $#uniques[@] > size )) &&
lines+=( "$displays[index]" )
(( size = $#uniques ))
(( size < max )) ||
break
done
displays=( "${(aO)lines[@]}" )
else
(( excess = $#displays[@] - max ))
(( excess > 0 )) &&
shift $excess displays
fi
local -P pop=
if (( is_incremental )); then
pop=-p
if [[ -z $words[CURRENT] ]]; then
displays=( ${(@aO)displays} )
else
local -a match=() mbegin=() mend=()
local -Pi num=0
# Fuzzy sort
for index in {1..$#displays[@]}; do
num=${(SM)${(M)displays[index]##$~numpat}##<->}
displays[index]=${history[$num]:/(#b)$~lbuffer($~query)$~rbuffer/$((
HISTNO - num + 64 * $#match[3] + 16 * mbegin[3] + 4 * $#match[1]
))}$'\0'$displays[index]
done
displays=( ${${(@n)displays}[@]##<->$'\0'} )
fi
fi
(( excess = $#displays[@] - list_lines ))
(( excess > 0 )) &&
shift $pop $excess displays
# To avoid wrapping, each completion should be one char less than terminal width.
displays=( ${(@mr:COLUMNS-1:)displays} )
local -Pa matches=()
for index in "${(MS)displays[@]##<->}"; do
matches+=( "${${history[$index]##$~lbuffer}%%$~rbuffer}" )
done
if [[ -z $matches ]]; then
return 1
fi
local -Pa suf=( -S '' )
if [[ $WIDGETSTYLE == *-select* && $#matches[@] > 1 ]] &&
zstyle -T ":autocomplete:${curcontext}:history-lines" add-semicolon; then
suf=( -S ';' -R _autocomplete__history_lines_suffix )
fi
local tag=history-lines
_comp_tags=" $tag"
local _comp_no_ignore=1
local -a expl=()
_description -2V $tag expl ''
builtin compadd "$suf[@]" -QU -ld displays "$expl[@]" -a matches
}
if is-at-least 5.9; then
_autocomplete__history_lines_suffix() {
if [[ SUFFIX_ACTIVE -ne 0 && $WIDGET != history-search-backward ]]; then
LBUFFER="$LBUFFER[1,SUFFIX_START]"
RBUFFER="$RBUFFER[SUFFIX_END,-1]"
fi
}
else
_autocomplete__history_lines_suffix() {
[[ $KEYS[-1] != $'\C-@' ]] && LBUFFER=$LBUFFER[1,-1-$1]
}
fi
_autocomplete__history_lines "$@"

View File

@@ -0,0 +1,38 @@
#autoload
zmodload -Fa zsh/parameter p:functions
# Don't run more than once.
(( _matcher_num > 1 )) &&
return 1
local -aU files
local -a expl expl_dirs expl_files displ
local -Pi ret i
local -P singular plural tag
.autocomplete:async:list-choices:max-lines
chpwd_recent_filehandler
files=( "$reply[@]" )
# -V: don't sort
_description -V recent-directories expl_dirs 'recent directory'
_description -V recent-files expl_files 'recent file'
_comp_tags+=' recent-directories recent-files'
ret=1
for (( i = 1 ; i <= $#files && compstate[list_lines] < _autocomplete__max_lines ; i++ )); do
displ=( "$files[i]" )
if [[ -d $files[i] ]]; then
expl=( "$expl_dirs[@]" )
else
expl=( "$expl_files[@]" )
fi
compadd "$expl[@]" -ld displ -P "${${displ[1]:h}%/}/" -fW "${${files[i]:h}%/}/" \
-- "$files[i]:t" &&
ret=0
done
return ret

View File

@@ -0,0 +1,15 @@
#autoload
local -Pa comptags=() spacetags=()
if [[ $compstate[old_list] == keep ]]; then
comptags=( $=_lastcomp[tags] )
else
comptags=( $=_comp_tags )
fi
comptags=( ${(u)comptags} )
local -a match mbegin mend
builtin zstyle -a ":autocomplete:$WIDGET:" add-space spacetags ||
spacetags=( executables aliases functions builtins reserved-words commands )
[[ -n ${comptags:*spacetags} ]]

View File

@@ -0,0 +1,9 @@
#autoload
local -a match=() mbegin=() mend=() # `zstyle` for some reason assigns these.
[[ $_completer == _expand ]] &&
return 1
[[ $WIDGET == *insert-unambiguous* ]] ||
builtin zstyle -t ":autocomplete:$curcontext" insert-unambiguous

View File

@@ -0,0 +1,43 @@
#autoload
[[ $_comp_tags == *\ (history-lines|recent-)* ]] &&
return 1
# Is not going to be correct.
[[ -v _autocomplete__partial_list ]] &&
return 1
# No need to update.
[[ $compstate[old_list] == keep ]] &&
return 1
# Doesn't make sense to show.
[[ compstate[nmatches] -lt 2 || $_completer == expand ]] &&
return 1
# Nothing to insert.
[[ -z $compstate[unambiguous] ]] &&
return 1
# Substring is already present.
local -P word=$IPREFIX$PREFIX$SUFFIX$ISUFFIX
[[ -n $word && $word == *$compstate[unambiguous]* ]] &&
return 1
local -P tag=unambiguous
_tags $tag
_tags ||
return
_requested $tag ||
return
# Retrieve highlight value.
local format
zstyle -s ":completion:${curcontext}:unambiguous" format format ||
format=$'%{\e[0;2m%}%Bcommon substring:%b %0F%11K%d%f%k'
zformat -F format "$format" "d:$compstate[unambiguous]"
builtin compadd -J "$tag" -x "$format"
false