Skip to content
Myr

completion.bash

This file

Path

shell/completion.bash

381 lines · 10.0 KiB · Shell

Last changed by

[bash] Enable environment variable completion for printenvJunegunn Choibefore adoptionf38a7f7

History of this file

Take it

The walk stopped after 200 commits: lines older than 885cd8f point at it.

[make] Add loongarch64 support (#2857)znleybefore adoption885cd8f

lines 1–39why, one step back
1# ____ ____
2# / __/___ / __/3# / /_/_ / / /_4# / __/ / /_/ __/5# /_/ /___/_/ completion.bash6#7# - $FZF_TMUX (default: 0)8# - $FZF_TMUX_OPTS (default: empty)9# - $FZF_COMPLETION_TRIGGER (default: '**')10# - $FZF_COMPLETION_OPTS (default: empty)1112if [[ $- =~ i ]]; then1314# To use custom commands instead of find, override _fzf_compgen_{path,dir}15if ! declare -f _fzf_compgen_path > /dev/null; then16 _fzf_compgen_path() {17 echo "$1"18 command find -L "$1" \19 -name .git -prune -o -name .hg -prune -o -name .svn -prune -o \( -type d -o -type f -o -type l \) \20 -a -not -path "$1" -print 2> /dev/null | sed 's@^\./@@'21 }22fi2324if ! declare -f _fzf_compgen_dir > /dev/null; then25 _fzf_compgen_dir() {26 command find -L "$1" \27 -name .git -prune -o -name .hg -prune -o -name .svn -prune -o -type d \28 -a -not -path "$1" -print 2> /dev/null | sed 's@^\./@@'29 }30fi3132###########################################################3334# To redraw line after fzf closes (printf '\e[5n')35bind '"\e[0n": redraw-current-line' 2> /dev/null3637__fzf_comprun() {38 if [[ "$(type -t _fzf_comprun 2>&1)" = function ]]; then39 _fzf_comprun "$@"

[shell] Make bash/zsh completion and bindings work with 'set -u' (#2999)John Fred Fadrigalanbefore adoption4603d54

line 40why, one step back
40 elif [[ -n "${TMUX_PANE-}" ]] && { [[ "${FZF_TMUX:-0}" != 0 ]] || [[ -n "${FZF_TMUX_OPTS-}" ]]; }; then

[make] Add loongarch64 support (#2857)znleybefore adoption885cd8f

lines 41–57why, one step back
41 shift
42 fzf-tmux ${FZF_TMUX_OPTS:--d${FZF_TMUX_HEIGHT:-40%}} -- "$@"43 else44 shift45 fzf "$@"46 fi47}4849__fzf_orig_completion() {50 local l comp f cmd51 while read -r l; do52 if [[ "$l" =~ ^(.*\ -F)\ *([^ ]*).*\ ([^ ]*)$ ]]; then53 comp="${BASH_REMATCH[1]}"54 f="${BASH_REMATCH[2]}"55 cmd="${BASH_REMATCH[3]}"56 [[ "$f" = _fzf_* ]] && continue57 printf -v "_fzf_orig_completion_${cmd//[^A-Za-z0-9_]/_}" "%s" "${comp} %s ${cmd} #${f}"

[shell] Make bash/zsh completion and bindings work with 'set -u' (#2999)John Fred Fadrigalanbefore adoption4603d54

lines 58–59why, one step back
58 if [[ "$l" = *" -o nospace "* ]] && [[ ! "${__fzf_nospace_commands-}" = *" $cmd "* ]]; then
59 __fzf_nospace_commands="${__fzf_nospace_commands-} $cmd "

[make] Add loongarch64 support (#2857)znleybefore adoption885cd8f

lines 60–141why, one step back
60 fi
61 fi62 done63}6465_fzf_opts_completion() {66 local cur prev opts67 COMPREPLY=()68 cur="${COMP_WORDS[COMP_CWORD]}"69 prev="${COMP_WORDS[COMP_CWORD-1]}"70 opts="71 -x --extended72 -e --exact73 --algo74 -i +i75 -n --nth76 --with-nth77 -d --delimiter78 +s --no-sort79 --tac80 --tiebreak81 -m --multi82 --no-mouse83 --bind84 --cycle85 --no-hscroll86 --jump-labels87 --height88 --literal89 --reverse90 --margin91 --inline-info92 --prompt93 --pointer94 --marker95 --header96 --header-lines97 --ansi98 --tabstop99 --color100 --no-bold101 --history102 --history-size103 --preview104 --preview-window105 -q --query106 -1 --select-1107 -0 --exit-0108 -f --filter109 --print-query110 --expect111 --sync"112113 case "${prev}" in114 --tiebreak)115 COMPREPLY=( $(compgen -W "length begin end index" -- "$cur") )116 return 0117 ;;118 --color)119 COMPREPLY=( $(compgen -W "dark light 16 bw" -- "$cur") )120 return 0121 ;;122 --history)123 COMPREPLY=()124 return 0125 ;;126 esac127128 if [[ "$cur" =~ ^-|\+ ]]; then129 COMPREPLY=( $(compgen -W "${opts}" -- "$cur") )130 return 0131 fi132133 return 0134}135136_fzf_handle_dynamic_completion() {137 local cmd orig_var orig ret orig_cmd orig_complete138 cmd="$1"139 shift140 orig_cmd="$1"141 orig_var="_fzf_orig_completion_$cmd"

[shell] Make bash/zsh completion and bindings work with 'set -u' (#2999)John Fred Fadrigalanbefore adoption4603d54

lines 142–143why, one step back
142 orig="${!orig_var-}"
143 orig="${orig##*#}"

[make] Add loongarch64 support (#2857)znleybefore adoption885cd8f

lines 144–145why, one step back
144 if [[ -n "$orig" ]] && type "$orig" > /dev/null 2>&1; then
145 $orig "$@"

[shell] Make bash/zsh completion and bindings work with 'set -u' (#2999)John Fred Fadrigalanbefore adoption4603d54

line 146why, one step back
146 elif [[ -n "${_fzf_completion_loader-}" ]]; then

[make] Add loongarch64 support (#2857)znleybefore adoption885cd8f

lines 147–152why, one step back
147 orig_complete=$(complete -p "$orig_cmd" 2> /dev/null)
148 _completion_loader "$@"149 ret=$?150 # _completion_loader may not have updated completion for the command151 if [[ "$(complete -p "$orig_cmd" 2> /dev/null)" != "$orig_complete" ]]; then152 __fzf_orig_completion < <(complete -p "$orig_cmd" 2> /dev/null)

[shell] Make bash/zsh completion and bindings work with 'set -u' (#2999)John Fred Fadrigalanbefore adoption4603d54

line 153why, one step back
153 if [[ "${__fzf_nospace_commands-}" = *" $orig_cmd "* ]]; then

[make] Add loongarch64 support (#2857)znleybefore adoption885cd8f

lines 154–164why, one step back
154 eval "${orig_complete/ -F / -o nospace -F }"
155 else156 eval "$orig_complete"157 fi158 fi159 return $ret160 fi161}162163__fzf_generic_path_completion() {164 local cur base dir leftover matches trigger cmd

[bash] Fix 'possible retry loop' problem of bash-completion (#2891)Bob Matcukbefore adoption68cf393

lines 165–169why, one step back
165 cmd="${COMP_WORDS[0]}"
166 if [[ $cmd == \\* ]]; then167 cmd="${cmd:1}"168 fi169 cmd="${cmd//[^A-Za-z0-9_=]/_}"

[make] Add loongarch64 support (#2857)znleybefore adoption885cd8f

lines 170–176why, one step back
170 COMPREPLY=()
171 trigger=${FZF_COMPLETION_TRIGGER-'**'}172 cur="${COMP_WORDS[COMP_CWORD]}"173 if [[ "$cur" == *"$trigger" ]]; then174 base=${cur:0:${#cur}-${#trigger}}175 eval "base=$base"176

[shell] Make bash/zsh completion and bindings work with 'set -u' (#2999)John Fred Fadrigalanbefore adoption4603d54

line 177why, one step back
177 dir=

[make] Add loongarch64 support (#2857)znleybefore adoption885cd8f

lines 178–184why, one step back
178 [[ $base = *"/"* ]] && dir="$base"
179 while true; do180 if [[ -z "$dir" ]] || [[ -d "$dir" ]]; then181 leftover=${base/#"$dir"}182 leftover=${leftover/#\/}183 [[ -z "$dir" ]] && dir='.'184 [[ "$dir" != "/" ]] && dir="${dir/%\//}"

[shell] Make bash/zsh completion and bindings work with 'set -u' (#2999)John Fred Fadrigalanbefore adoption4603d54

line 185why, one step back
185 matches=$(eval "$1 $(printf %q "$dir")" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse --bind=ctrl-z:ignore ${FZF_DEFAULT_OPTS-} ${FZF_COMPLETION_OPTS-} $2" __fzf_comprun "$4" -q "$leftover" | while read -r item; do

[completion] Remove extra trailing slash on directory completionJunegunn Choibefore adoption6532b3e

line 186why, one step back
186 printf "%q " "${item%$3}$3"

[make] Add loongarch64 support (#2857)znleybefore adoption885cd8f

lines 187–188why, one step back
187 done)
188 matches=${matches% }

[shell] Make bash/zsh completion and bindings work with 'set -u' (#2999)John Fred Fadrigalanbefore adoption4603d54

line 189why, one step back
189 [[ -z "$3" ]] && [[ "${__fzf_nospace_commands-}" = *" ${COMP_WORDS[0]} "* ]] && matches="$matches "

[make] Add loongarch64 support (#2857)znleybefore adoption885cd8f

lines 190–240why, one step back
190 if [[ -n "$matches" ]]; then
191 COMPREPLY=( "$matches" )192 else193 COMPREPLY=( "$cur" )194 fi195 printf '\e[5n'196 return 0197 fi198 dir=$(dirname "$dir")199 [[ "$dir" =~ /$ ]] || dir="$dir"/200 done201 else202 shift203 shift204 shift205 _fzf_handle_dynamic_completion "$cmd" "$@"206 fi207}208209_fzf_complete() {210 # Split arguments around --211 local args rest str_arg i sep212 args=("$@")213 sep=214 for i in "${!args[@]}"; do215 if [[ "${args[$i]}" = -- ]]; then216 sep=$i217 break218 fi219 done220 if [[ -n "$sep" ]]; then221 str_arg=222 rest=("${args[@]:$((sep + 1)):${#args[@]}}")223 args=("${args[@]:0:$sep}")224 else225 str_arg=$1226 args=()227 shift228 rest=("$@")229 fi230231 local cur selected trigger cmd post232 post="$(caller 0 | awk '{print $2}')_post"233 type -t "$post" > /dev/null 2>&1 || post=cat234235 cmd="${COMP_WORDS[0]//[^A-Za-z0-9_=]/_}"236 trigger=${FZF_COMPLETION_TRIGGER-'**'}237 cur="${COMP_WORDS[COMP_CWORD]}"238 if [[ "$cur" == *"$trigger" ]]; then239 cur=${cur:0:${#cur}-${#trigger}}240

[shell] Make bash/zsh completion and bindings work with 'set -u' (#2999)John Fred Fadrigalanbefore adoption4603d54

line 241why, one step back
241 selected=$(FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse --bind=ctrl-z:ignore ${FZF_DEFAULT_OPTS-} ${FZF_COMPLETION_OPTS-} $str_arg" __fzf_comprun "${rest[0]}" "${args[@]}" -q "$cur" | $post | tr '\n' ' ')

[make] Add loongarch64 support (#2857)znleybefore adoption885cd8f

lines 242–283why, one step back
242 selected=${selected% } # Strip trailing space not to repeat "-o nospace"
243 if [[ -n "$selected" ]]; then244 COMPREPLY=("$selected")245 else246 COMPREPLY=("$cur")247 fi248 printf '\e[5n'249 return 0250 else251 _fzf_handle_dynamic_completion "$cmd" "${rest[@]}"252 fi253}254255_fzf_path_completion() {256 __fzf_generic_path_completion _fzf_compgen_path "-m" "" "$@"257}258259# Deprecated. No file only completion.260_fzf_file_completion() {261 _fzf_path_completion "$@"262}263264_fzf_dir_completion() {265 __fzf_generic_path_completion _fzf_compgen_dir "" "/" "$@"266}267268_fzf_complete_kill() {269 _fzf_proc_completion "$@"270}271272_fzf_proc_completion() {273 _fzf_complete -m --preview 'echo {}' --preview-window down:3:wrap --min-height 15 -- "$@" < <(274 command ps -ef | sed 1d275 )276}277278_fzf_proc_completion_post() {279 awk '{print $2}'280}281282_fzf_host_completion() {283 _fzf_complete +m -- "$@" < <(

[completion] ssh: Remove values with '%' (#2548)lbesnardbefore adoptiona8e7021

line 284why, one step back
284 command cat <(command tail -n +1 ~/.ssh/config ~/.ssh/config.d/* /etc/ssh/ssh_config 2> /dev/null | command grep -i '^\s*host\(name\)\? ' | awk '{for (i = 2; i <= NF; i++) print $1 " " $i}' | command grep -v '[*?%]') \

[make] Add loongarch64 support (#2857)znleybefore adoption885cd8f

lines 285–292why, one step back
285 <(command grep -oE '^[[a-z0-9.,:-]+' ~/.ssh/known_hosts | tr ',' '\n' | tr -d '[' | awk '{ print $1 " " $1 }') \
286 <(command grep -v '^\s*\(#\|$\)' /etc/hosts | command grep -Fv '0.0.0.0') |287 awk '{if (length($2) > 0) {print $2}}' | sort -u288 )289}290291_fzf_var_completion() {292 _fzf_complete -m -- "$@" < <(

[bash] Fix completion of var or alias containing newlines (#2952)knutzebefore adoptionb9e6e79

line 293why, one step back
293 declare -xp | sed -En 's|^declare [^ ]+ ([^=]+).*|\1|p'

[make] Add loongarch64 support (#2857)znleybefore adoption885cd8f

lines 294–298why, one step back
294 )
295}296297_fzf_alias_completion() {298 _fzf_complete -m -- "$@" < <(

[bash] Fix completion of var or alias containing newlines (#2952)knutzebefore adoptionb9e6e79

line 299why, one step back
299 alias | sed -En 's|^alias ([^=]+).*|\1|p'

[make] Add loongarch64 support (#2857)znleybefore adoption885cd8f

lines 300–304why, one step back
300 )
301}302303# fzf options304complete -o default -F _fzf_opts_completion fzf

[bash] Fix `fzf-tmux` to have `fzf`'s completion (#2871)Jonathan Zacshbefore adoptionc79c306

lines 305–308why, one step back
305# fzf-tmux is a thin fzf wrapper that has only a few more options than fzf
306# itself. As a quick improvement we take fzf's completion. Adding the few extra307# fzf-tmux specific options (like `-w WIDTH`) are left as a future patch.308complete -o default -F _fzf_opts_completion fzf-tmux

[make] Add loongarch64 support (#2857)znleybefore adoption885cd8f

lines 309–312why, one step back
309
310d_cmds="${FZF_COMPLETION_DIR_COMMANDS:-cd pushd rmdir}"311a_cmds="312 awk cat diff diff3

Add Helix editor to bash autocompletion (#3137)Nachum Barcohenbefore adoptione44f64a

line 313why, one step back
313 emacs emacsclient ex file ftp g++ gcc gvim head hg hx java

[make] Add loongarch64 support (#2857)znleybefore adoption885cd8f

lines 314–333why, one step back
314 javac ld less more mvim nvim patch perl python ruby
315 sed sftp sort source tail tee uniq vi view vim wc xdg-open316 basename bunzip2 bzip2 chmod chown curl cp dirname du317 find git grep gunzip gzip hg jar318 ln ls mv open rm rsync scp319 svn tar unzip zip"320321# Preserve existing completion322__fzf_orig_completion < <(complete -p $d_cmds $a_cmds 2> /dev/null)323324if type _completion_loader > /dev/null 2>&1; then325 _fzf_completion_loader=1326fi327328__fzf_defc() {329 local cmd func opts orig_var orig def330 cmd="$1"331 func="$2"332 opts="$3"333 orig_var="_fzf_orig_completion_${cmd//[^A-Za-z0-9_]/_}"

[shell] Make bash/zsh completion and bindings work with 'set -u' (#2999)John Fred Fadrigalanbefore adoption4603d54

line 334why, one step back
334 orig="${!orig_var-}"

[make] Add loongarch64 support (#2857)znleybefore adoption885cd8f

lines 335–374why, one step back
335 if [[ -n "$orig" ]]; then
336 printf -v def "$orig" "$func"337 eval "$def"338 else339 complete -F "$func" $opts "$cmd"340 fi341}342343# Anything344for cmd in $a_cmds; do345 __fzf_defc "$cmd" _fzf_path_completion "-o default -o bashdefault"346done347348# Directory349for cmd in $d_cmds; do350 __fzf_defc "$cmd" _fzf_dir_completion "-o nospace -o dirnames"351done352353unset cmd d_cmds a_cmds354355_fzf_setup_completion() {356 local kind fn cmd357 kind=$1358 fn=_fzf_${1}_completion359 if [[ $# -lt 2 ]] || ! type -t "$fn" > /dev/null; then360 echo "usage: ${FUNCNAME[0]} path|dir|var|alias|host|proc COMMANDS..."361 return 1362 fi363 shift364 __fzf_orig_completion < <(complete -p "$@" 2> /dev/null)365 for cmd in "$@"; do366 case "$kind" in367 dir) __fzf_defc "$cmd" "$fn" "-o nospace -o dirnames" ;;368 var) __fzf_defc "$cmd" "$fn" "-o default -o nospace -v" ;;369 alias) __fzf_defc "$cmd" "$fn" "-a" ;;370 *) __fzf_defc "$cmd" "$fn" "-o default -o bashdefault" ;;371 esac372 done373}374

[shell] 'kill' completion will now require trigger sequence (**)Junegunn Choibefore adoption5259435

line 375why, one step back
375# Environment variables / Aliases / Hosts / Process

[bash] Enable environment variable completion for printenvJunegunn Choibefore adoptionf38a7f7

line 376why, one step back
376_fzf_setup_completion 'var' export unset printenv

[make] Add loongarch64 support (#2857)znleybefore adoption885cd8f

lines 377–378why, one step back
377_fzf_setup_completion 'alias' unalias
378_fzf_setup_completion 'host' ssh telnet

[shell] 'kill' completion will now require trigger sequence (**)Junegunn Choibefore adoption5259435

line 379why, one step back
379_fzf_setup_completion 'proc' kill

[make] Add loongarch64 support (#2857)znleybefore adoption885cd8f

lines 380–381why, one step back
380
381fi