Make completion.bash load faster

* Reduce number of `__fzf_orig_completion < <(complete -p "$@" 2> /dev/null)`s
* Clean up options in fzf completion
* Remove telnet completion
pull/2131/head
Junegunn Choi 3 weeks ago
parent fddbfe7b0e
commit 767f1255ab
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627

@ -100,128 +100,77 @@ _fzf_opts_completion() {
prev="${COMP_WORDS[COMP_CWORD-1]}" prev="${COMP_WORDS[COMP_CWORD-1]}"
opts=" opts="
-h --help -h --help
-x --extended
-e --exact -e --exact
--extended-exact
+x --no-extended +x --no-extended
+e --no-exact
-q --query -q --query
-f --filter -f --filter
--literal --literal
--no-literal
--algo
--scheme --scheme
--expect --expect
--no-expect --disabled
--enabled --no-phony
--disabled --phony
--tiebreak --tiebreak
--bind --bind
--color --color
--toggle-sort
-d --delimiter -d --delimiter
-n --nth -n --nth
--with-nth --with-nth
-s --sort
+s --no-sort +s --no-sort
--track --track
--no-track
--tac --tac
--no-tac
-i -i
+i +i
-m --multi -m --multi
+m --no-multi
--ansi --ansi
--no-ansi
--no-mouse --no-mouse
+c --no-color +c --no-color
+2 --no-256
--black
--no-black
--bold
--no-bold --no-bold
--layout --layout
--reverse --reverse
--no-reverse
--cycle --cycle
--no-cycle
--keep-right --keep-right
--no-keep-right
--hscroll
--no-hscroll --no-hscroll
--hscroll-off --hscroll-off
--scroll-off --scroll-off
--filepath-word --filepath-word
--no-filepath-word
--info --info
--no-info
--inline-info
--no-inline-info
--separator --separator
--no-separator --no-separator
--scrollbar
--no-scrollbar --no-scrollbar
--jump-labels --jump-labels
-1 --select-1 -1 --select-1
+1 --no-select-1
-0 --exit-0 -0 --exit-0
+0 --no-exit-0
--read0 --read0
--no-read0
--print0 --print0
--no-print0
--print-query --print-query
--no-print-query
--prompt --prompt
--pointer --pointer
--marker --marker
--sync --sync
--no-sync
--async
--no-history
--history --history
--history-size --history-size
--no-header
--no-header-lines
--header --header
--header-lines --header-lines
--header-first --header-first
--no-header-first
--ellipsis --ellipsis
--preview --preview
--no-preview
--preview-window --preview-window
--height --height
--min-height --min-height
--no-height
--no-margin
--no-padding
--no-border
--border --border
--no-border-label
--border-label --border-label
--border-label-pos --border-label-pos
--no-preview-label
--preview-label --preview-label
--preview-label-pos --preview-label-pos
--no-unicode --no-unicode
--unicode
--margin --margin
--padding --padding
--tabstop --tabstop
--listen --listen
--no-listen
--clear
--no-clear --no-clear
--version --version
--" --"
case "${prev}" in case "${prev}" in
--algo)
COMPREPLY=( $(compgen -W "v1 v2" -- "$cur") )
return 0
;;
--scheme) --scheme)
COMPREPLY=( $(compgen -W "default path history" -- "$cur") ) COMPREPLY=( $(compgen -W "default path history" -- "$cur") )
return 0 return 0
@ -524,9 +473,10 @@ a_cmds="
find git grep gunzip gzip hg jar find git grep gunzip gzip hg jar
ln ls mv open rm rsync scp ln ls mv open rm rsync scp
svn tar unzip zip" svn tar unzip zip"
v_cmds="export unset printenv"
# Preserve existing completion # Preserve existing completion
__fzf_orig_completion < <(complete -p $d_cmds $a_cmds ssh 2> /dev/null) __fzf_orig_completion < <(complete -p $d_cmds $a_cmds $v_cmds unalias kill ssh 2> /dev/null)
if type _comp_load > /dev/null 2>&1; then if type _comp_load > /dev/null 2>&1; then
# _comp_load was added in bash-completion 2.12 to replace _completion_loader. # _comp_load was added in bash-completion 2.12 to replace _completion_loader.
@ -562,10 +512,21 @@ for cmd in $d_cmds; do
__fzf_defc "$cmd" _fzf_dir_completion "-o bashdefault -o nospace -o dirnames" __fzf_defc "$cmd" _fzf_dir_completion "-o bashdefault -o nospace -o dirnames"
done done
# Variables
for cmd in $v_cmds; do
__fzf_defc "$cmd" _fzf_var_completion "-o default -o nospace -v"
done
# Aliases
__fzf_defc unalias _fzf_alias_completion "-a"
# Processes
__fzf_defc kill _fzf_proc_completion "-o default -o bashdefault"
# ssh # ssh
__fzf_defc ssh _fzf_complete_ssh "-o default -o bashdefault" __fzf_defc ssh _fzf_complete_ssh "-o default -o bashdefault"
unset cmd d_cmds a_cmds unset cmd d_cmds a_cmds v_cmds
_fzf_setup_completion() { _fzf_setup_completion() {
local kind fn cmd local kind fn cmd
@ -587,10 +548,4 @@ _fzf_setup_completion() {
done done
} }
# Environment variables / Aliases / Hosts / Process
_fzf_setup_completion 'var' export unset printenv
_fzf_setup_completion 'alias' unalias
_fzf_setup_completion 'host' telnet
_fzf_setup_completion 'proc' kill
fi fi

Loading…
Cancel
Save