#!/bin/zsh zmodload -Fa zsh/files b:zf_rm zmodload -F zsh/parameter p:funcstack p:functions builtin autoload -Uz is-at-least typeset -ga _autocomplete__compdef=() compdef() { typeset -ga _autocomplete__compdef=( $_autocomplete__compdef[@] "${(j: :)${(@q+)@}}" ) } [[ -v functions[_bash_complete] ]] || _bash_complete compgen complete () { unfunction _bash_complete compgen complete builtin autoload +X -Uz bashcompinit bashcompinit bashcompinit() { : } ${(%):-%N} "$@" } ${0}:precmd() { emulate -L zsh setopt $_autocomplete__func_opts[@] [[ -v CDPATH && -z $CDPATH ]] && unset CDPATH cdpath # Decrease Oh My Zsh start-up time. See below. local -Pa omzdump=() [[ -v ZSH_COMPDUMP && -r $ZSH_COMPDUMP ]] && omzdump=( ${(f)"$( < $ZSH_COMPDUMP )"} ) typeset -g \ _comp_dumpfile=${_comp_dumpfile:-${ZSH_COMPDUMP:-${XDG_CACHE_HOME:-$HOME/.cache}/zsh/compdump}} if [[ -v _comps[-command-] && $_comps[-command-] != _autocomplete__command ]]; then zf_rm -f $_comp_dumpfile else # Check if our most recently modified completion function is newer than the comp dump file. local -Pa newest=( ~autocomplete/Completions/_*~*.zwc(N-.omY1) ) if [[ $newest[1] -nt $_comp_dumpfile ]]; then zf_rm -f $_comp_dumpfile fi fi if [[ ! -v _comp_setup ]] || [[ ! -r $_comp_dumpfile ]]; then unfunction compdef compinit 2> /dev/null bindkey() { : } { builtin autoload +X -Uz compinit local -a compargs=() zstyle -a ':autocomplete::compinit' arguments compargs compinit -d "$_comp_dumpfile" "$compargs[@]" } always { unfunction bindkey } bindkey '^Xh' _complete_help # Prevent Oh My Zsh from deleting comp dump file. (( ${#omzdump[@]} > 0 )) && tee -a "$ZSH_COMPDUMP" &> /dev/null < /dev/null _autocomplete__unambiguous compstate[list_max]=0 MENUSCROLL=0 } .autocomplete__patch _complete _complete() { local -i nmatches=$compstate[nmatches] PREFIX=$PREFIX$SUFFIX SUFFIX= autocomplete:_complete:old "$@" # WORKAROUND: Some completion functions mistakenly don't return 0 when they have succeeded. (( compstate[nmatches] > nmatches )) } ## # WORKAROUND: _approximate won't do corrections if there already is a function called 'compadd'. # .autocomplete__patch _approximate _approximate() { { [[ -v functions[compadd] ]] && functions[autocomplete:compadd:old]="$functions[compadd]" functions[compadd]="$functions[autocomplete:approximate:compadd]" autocomplete:_approximate:old } always { unfunction compadd 2> /dev/null if [[ -v functions[autocomplete:compadd:old] ]]; then functions[compadd]="$functions[autocomplete:compadd:old]" unfunction autocomplete:compadd:old fi } } autocomplete:approximate:compadd() { local ppre="$argv[(I)-p]" [[ ${argv[(I)-[a-zA-Z]#U[a-zA-Z]#]} -eq 0 && "${#:-$PREFIX$SUFFIX}" -le _comp_correct ]] && return if [[ "$PREFIX" = \~* && ( ppre -eq 0 || "$argv[ppre+1]" != \~* ) ]]; then PREFIX="~(#a${_comp_correct})${PREFIX[2,-1]}" else PREFIX="(#a${_comp_correct})$PREFIX" fi if [[ -v functions[autocomplete:compadd:old] ]]; then autocomplete:compadd:old "$@" else builtin compadd "$@" fi } }