completion.bash
This file
Path
shell/completion.bash
380 lines · 9.7 KiB · Shell
Last changed by
[bash-completion] Optimize __fzf_orig_completion_filterTomas Janousekbefore adoptionef2c29d
History of this fileTake it
The walk stopped after 200 commits: lines older than f51d61d point at it.
[zsh] Prevent the current directory from appearing as `~dir` in prompts (#1774)midchildanbefore adoptionf51d61d
lines 1–4why, one step back1# ____ ____2# / __/___ / __/3# / /_/_ / / /_4# / __/ / /_/ __/[fzf-tmux] Add option to start fzf in tmux popup windowJunegunn Choibefore adoptionbf65e8c
line 5why, one step back5# /_/ /___/_/ completion.bash[zsh] Prevent the current directory from appearing as `~dir` in prompts (#1774)midchildanbefore adoptionf51d61d
lines 6–7why, one step back6#7# - $FZF_TMUX (default: 0)[fzf-tmux] Add option to start fzf in tmux popup windowJunegunn Choibefore adoptionbf65e8c
line 8why, one step back8# - $FZF_TMUX_OPTS (default: empty)[zsh] Prevent the current directory from appearing as `~dir` in prompts (#1774)midchildanbefore adoptionf51d61d
lines 9–18why, one step back9# - $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" \[completion] Ignore hg repos (#1777)John Purnellbefore adoption357e82e
line 19why, one step back19 -name .git -prune -o -name .hg -prune -o -name .svn -prune -o \( -type d -o -type f -o -type l \) \[zsh] Prevent the current directory from appearing as `~dir` in prompts (#1774)midchildanbefore adoptionf51d61d
lines 20–26why, one step back20 -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" \[completion] Ignore hg repos (#1777)John Purnellbefore adoption357e82e
line 27why, one step back27 -name .git -prune -o -name .hg -prune -o -name .svn -prune -o -type d \[zsh] Prevent the current directory from appearing as `~dir` in prompts (#1774)midchildanbefore adoptionf51d61d
lines 28–36why, one step back28 -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'36[completion] Allow users to customize fzf options via _fzf_comprunJunegunn Choibefore adoption5215415
lines 37–39why, one step back37__fzf_comprun() {38 if [ "$(type -t _fzf_comprun 2>&1)" = function ]; then39 _fzf_comprun "$@"[fzf-tmux] Fall back to plain fzf when split failedJunegunn Choibefore adoption540bfd7
line 40why, one step back40 elif [ -n "$TMUX_PANE" ] && { [ "${FZF_TMUX:-0}" != 0 ] || [ -n "$FZF_TMUX_OPTS" ]; }; then[completion] Allow users to customize fzf options via _fzf_comprunJunegunn Choibefore adoption5215415
line 41why, one step back41 shift[fzf-tmux] Add option to start fzf in tmux popup windowJunegunn Choibefore adoptionbf65e8c
line 42why, one step back42 fzf-tmux ${FZF_TMUX_OPTS:--d${FZF_TMUX_HEIGHT:-40%}} -- "$@"[completion] Allow users to customize fzf options via _fzf_comprunJunegunn Choibefore adoption5215415
lines 43–46why, one step back43 else44 shift45 fzf "$@"46 fi[zsh] Prevent the current directory from appearing as `~dir` in prompts (#1774)midchildanbefore adoptionf51d61d
lines 47–48why, one step back47}48[bash-completion] Optimize __fzf_orig_completion_filterTomas Janousekbefore adoptionef2c29d
lines 49–61why, one step back49__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 export "_fzf_orig_completion_${cmd//[^A-Za-z0-9_]/_}=${comp} %s ${cmd} #${f}"57 if [[ "$l" = *" -o nospace "* ]] && [[ ! "$__fzf_nospace_commands" = *" $cmd "* ]]; then58 __fzf_nospace_commands="$__fzf_nospace_commands $cmd "59 fi60 fi61 done[zsh] Prevent the current directory from appearing as `~dir` in prompts (#1774)midchildanbefore adoptionf51d61d
lines 62–91why, one step back62}6364_fzf_opts_completion() {65 local cur prev opts66 COMPREPLY=()67 cur="${COMP_WORDS[COMP_CWORD]}"68 prev="${COMP_WORDS[COMP_CWORD-1]}"69 opts="70 -x --extended71 -e --exact72 --algo73 -i +i74 -n --nth75 --with-nth76 -d --delimiter77 +s --no-sort78 --tac79 --tiebreak80 -m --multi81 --no-mouse82 --bind83 --cycle84 --no-hscroll85 --jump-labels86 --height87 --literal88 --reverse89 --margin90 --inline-info91 --promptMake pointer and multi-select marker customizable (#1844)Hiroki Konishibefore adoption2a60edc
lines 92–93why, one step back92 --pointer93 --marker[zsh] Prevent the current directory from appearing as `~dir` in prompts (#1774)midchildanbefore adoptionf51d61d
lines 94–149why, one step back94 --header95 --header-lines96 --ansi97 --tabstop98 --color99 --no-bold100 --history101 --history-size102 --preview103 --preview-window104 -q --query105 -1 --select-1106 -0 --exit-0107 -f --filter108 --print-query109 --expect110 --sync"111112 case "${prev}" in113 --tiebreak)114 COMPREPLY=( $(compgen -W "length begin end index" -- "$cur") )115 return 0116 ;;117 --color)118 COMPREPLY=( $(compgen -W "dark light 16 bw" -- "$cur") )119 return 0120 ;;121 --history)122 COMPREPLY=()123 return 0124 ;;125 esac126127 if [[ "$cur" =~ ^-|\+ ]]; then128 COMPREPLY=( $(compgen -W "${opts}" -- "$cur") )129 return 0130 fi131132 return 0133}134135_fzf_handle_dynamic_completion() {136 local cmd orig_var orig ret orig_cmd orig_complete137 cmd="$1"138 shift139 orig_cmd="$1"140 orig_var="_fzf_orig_completion_$cmd"141 orig="${!orig_var##*#}"142 if [ -n "$orig" ] && type "$orig" > /dev/null 2>&1; then143 $orig "$@"144 elif [ -n "$_fzf_completion_loader" ]; then145 orig_complete=$(complete -p "$orig_cmd" 2> /dev/null)146 _completion_loader "$@"147 ret=$?148 # _completion_loader may not have updated completion for the command149 if [ "$(complete -p "$orig_cmd" 2> /dev/null)" != "$orig_complete" ]; then[bash-completion] Optimize __fzf_orig_completion_filterTomas Janousekbefore adoptionef2c29d
line 150why, one step back150 __fzf_orig_completion < <(complete -p "$orig_cmd" 2> /dev/null)[zsh] Prevent the current directory from appearing as `~dir` in prompts (#1774)midchildanbefore adoptionf51d61d
lines 151–161why, one step back151 if [[ "$__fzf_nospace_commands" = *" $orig_cmd "* ]]; then152 eval "${orig_complete/ -F / -o nospace -F }"153 else154 eval "$orig_complete"155 fi156 fi157 return $ret158 fi159}160161__fzf_generic_path_completion() {[completion] Allow users to customize fzf options via _fzf_comprunJunegunn Choibefore adoption5215415
line 162why, one step back162 local cur base dir leftover matches trigger cmd[zsh] Prevent the current directory from appearing as `~dir` in prompts (#1774)midchildanbefore adoptionf51d61d
lines 163–177why, one step back163 cmd="${COMP_WORDS[0]//[^A-Za-z0-9_=]/_}"164 COMPREPLY=()165 trigger=${FZF_COMPLETION_TRIGGER-'**'}166 cur="${COMP_WORDS[COMP_CWORD]}"167 if [[ "$cur" == *"$trigger" ]]; then168 base=${cur:0:${#cur}-${#trigger}}169 eval "base=$base"170171 [[ $base = *"/"* ]] && dir="$base"172 while true; do173 if [ -z "$dir" ] || [ -d "$dir" ]; then174 leftover=${base/#"$dir"}175 leftover=${leftover/#\/}176 [ -z "$dir" ] && dir='.'177 [ "$dir" != "/" ] && dir="${dir/%\//}"[completion] Allow users to customize fzf options via _fzf_comprunJunegunn Choibefore adoption5215415
line 178why, one step back178 matches=$(eval "$1 $(printf %q "$dir")" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_COMPLETION_OPTS $2" __fzf_comprun "$4" -q "$leftover" | while read -r item; do[zsh] Prevent the current directory from appearing as `~dir` in prompts (#1774)midchildanbefore adoptionf51d61d
lines 179–202why, one step back179 printf "%q$3 " "$item"180 done)181 matches=${matches% }182 [[ -z "$3" ]] && [[ "$__fzf_nospace_commands" = *" ${COMP_WORDS[0]} "* ]] && matches="$matches "183 if [ -n "$matches" ]; then184 COMPREPLY=( "$matches" )185 else186 COMPREPLY=( "$cur" )187 fi188 printf '\e[5n'189 return 0190 fi191 dir=$(dirname "$dir")192 [[ "$dir" =~ /$ ]] || dir="$dir"/193 done194 else195 shift196 shift197 shift198 _fzf_handle_dynamic_completion "$cmd" "$@"199 fi200}201202_fzf_complete() {Change custom fuzzy completion APIJunegunn Choibefore adoption50b7608
lines 203–223why, one step back203 # Split arguments around --204 local args rest str_arg i sep205 args=("$@")206 sep=207 for i in "${!args[@]}"; do208 if [[ "${args[$i]}" = -- ]]; then209 sep=$i210 break211 fi212 done213 if [[ -n "$sep" ]]; then214 str_arg=215 rest=("${args[@]:$((sep + 1)):${#args[@]}}")216 args=("${args[@]:0:$sep}")217 else218 str_arg=$1219 args=()220 shift221 rest=("$@")222 fi223[completion] Allow users to customize fzf options via _fzf_comprunJunegunn Choibefore adoption5215415
line 224why, one step back224 local cur selected trigger cmd post[zsh] Prevent the current directory from appearing as `~dir` in prompts (#1774)midchildanbefore adoptionf51d61d
lines 225–233why, one step back225 post="$(caller 0 | awk '{print $2}')_post"226 type -t "$post" > /dev/null 2>&1 || post=cat227228 cmd="${COMP_WORDS[0]//[^A-Za-z0-9_=]/_}"229 trigger=${FZF_COMPLETION_TRIGGER-'**'}230 cur="${COMP_WORDS[COMP_CWORD]}"231 if [[ "$cur" == *"$trigger" ]]; then232 cur=${cur:0:${#cur}-${#trigger}}233Change custom fuzzy completion APIJunegunn Choibefore adoption50b7608
line 234why, one step back234 selected=$(FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_COMPLETION_OPTS $str_arg" __fzf_comprun "${rest[0]}" "${args[@]}" -q "$cur" | $post | tr '\n' ' ')[zsh] Prevent the current directory from appearing as `~dir` in prompts (#1774)midchildanbefore adoptionf51d61d
lines 235–243why, one step back235 selected=${selected% } # Strip trailing space not to repeat "-o nospace"236 if [ -n "$selected" ]; then237 COMPREPLY=("$selected")238 else239 COMPREPLY=("$cur")240 fi241 printf '\e[5n'242 return 0243 elseChange custom fuzzy completion APIJunegunn Choibefore adoption50b7608
line 244why, one step back244 _fzf_handle_dynamic_completion "$cmd" "${rest[@]}"[zsh] Prevent the current directory from appearing as `~dir` in prompts (#1774)midchildanbefore adoptionf51d61d
lines 245–261why, one step back245 fi246}247248_fzf_path_completion() {249 __fzf_generic_path_completion _fzf_compgen_path "-m" "" "$@"250}251252# Deprecated. No file only completion.253_fzf_file_completion() {254 _fzf_path_completion "$@"255}256257_fzf_dir_completion() {258 __fzf_generic_path_completion _fzf_compgen_dir "" "/" "$@"259}260261_fzf_complete_kill() {[completion] Make kill completion more consistent with the othersJunegunn Choibefore adoptionc329279
lines 262–268why, one step back262 local trigger=${FZF_COMPLETION_TRIGGER-'**'}263 local cur="${COMP_WORDS[COMP_CWORD]}"264 if [[ -z "$cur" ]]; then265 COMP_WORDS[$COMP_CWORD]=$trigger266 elif [[ "$cur" != *"$trigger" ]]; then267 return 1268 fi[zsh] Prevent the current directory from appearing as `~dir` in prompts (#1774)midchildanbefore adoptionf51d61d
line 269why, one step back269[completion] Make kill completion more consistent with the othersJunegunn Choibefore adoptionc329279
lines 270–271why, one step back270 _fzf_proc_completion "$@"271}[zsh] Prevent the current directory from appearing as `~dir` in prompts (#1774)midchildanbefore adoptionf51d61d
line 272why, one step back272[completion] Make kill completion more consistent with the othersJunegunn Choibefore adoptionc329279
lines 273–276why, one step back273_fzf_proc_completion() {274 _fzf_complete -m --preview 'echo {}' --preview-window down:3:wrap --min-height 15 -- "$@" < <(275 command ps -ef | sed 1d276 )[zsh] Prevent the current directory from appearing as `~dir` in prompts (#1774)midchildanbefore adoptionf51d61d
lines 277–278why, one step back277}278[completion] Make kill completion more consistent with the othersJunegunn Choibefore adoptionc329279
lines 279–282why, one step back279_fzf_proc_completion_post() {280 awk '{print $2}'281}282[bash-completion] Fix default alias/variable completionJunegunn Choibefore adoptiond4ad4a2
line 283why, one step back283_fzf_host_completion() {Change custom fuzzy completion APIJunegunn Choibefore adoption50b7608
line 284why, one step back284 _fzf_complete +m -- "$@" < <([completion] Make host completion handle source files without EOLElvan Owenbefore adoption2986e64
line 285why, one step back285 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 '[*?]') \[zsh] Prevent the current directory from appearing as `~dir` in prompts (#1774)midchildanbefore adoptionf51d61d
lines 286–291why, one step back286 <(command grep -oE '^[[a-z0-9.,:-]+' ~/.ssh/known_hosts | tr ',' '\n' | tr -d '[' | awk '{ print $1 " " $1 }') \287 <(command grep -v '^\s*\(#\|$\)' /etc/hosts | command grep -Fv '0.0.0.0') |288 awk '{if (length($2) > 0) {print $2}}' | sort -u289 )290}291[bash-completion] Fix default alias/variable completionJunegunn Choibefore adoptiond4ad4a2
line 292why, one step back292_fzf_var_completion() {Change custom fuzzy completion APIJunegunn Choibefore adoption50b7608
line 293why, one step back293 _fzf_complete -m -- "$@" < <([zsh] Prevent the current directory from appearing as `~dir` in prompts (#1774)midchildanbefore adoptionf51d61d
lines 294–297why, one step back294 declare -xp | sed 's/=.*//' | sed 's/.* //'295 )296}297[bash-completion] Fix default alias/variable completionJunegunn Choibefore adoptiond4ad4a2
line 298why, one step back298_fzf_alias_completion() {Change custom fuzzy completion APIJunegunn Choibefore adoption50b7608
line 299why, one step back299 _fzf_complete -m -- "$@" < <([zsh] Prevent the current directory from appearing as `~dir` in prompts (#1774)midchildanbefore adoptionf51d61d
lines 300–318why, one step back300 alias | sed 's/=.*//' | sed 's/.* //'301 )302}303304# fzf options305complete -o default -F _fzf_opts_completion fzf306307d_cmds="${FZF_COMPLETION_DIR_COMMANDS:-cd pushd rmdir}"308a_cmds="309 awk cat diff diff3310 emacs emacsclient ex file ftp g++ gcc gvim head hg java311 javac ld less more mvim nvim patch perl python ruby312 sed sftp sort source tail tee uniq vi view vim wc xdg-open313 basename bunzip2 bzip2 chmod chown curl cp dirname du314 find git grep gunzip gzip hg jar315 ln ls mv open rm rsync scp316 svn tar unzip zip"317318# Preserve existing completion[bash-completion] Optimize __fzf_orig_completion_filterTomas Janousekbefore adoptionef2c29d
line 319why, one step back319__fzf_orig_completion < <(complete -p $d_cmds $a_cmds 2> /dev/null)[zsh] Prevent the current directory from appearing as `~dir` in prompts (#1774)midchildanbefore adoptionf51d61d
lines 320–349why, one step back320321if type _completion_loader > /dev/null 2>&1; then322 _fzf_completion_loader=1323fi324325__fzf_defc() {326 local cmd func opts orig_var orig def327 cmd="$1"328 func="$2"329 opts="$3"330 orig_var="_fzf_orig_completion_${cmd//[^A-Za-z0-9_]/_}"331 orig="${!orig_var}"332 if [ -n "$orig" ]; then333 printf -v def "$orig" "$func"334 eval "$def"335 else336 complete -F "$func" $opts "$cmd"337 fi338}339340# Anything341for cmd in $a_cmds; do342 __fzf_defc "$cmd" _fzf_path_completion "-o default -o bashdefault"343done344345# Directory346for cmd in $d_cmds; do347 __fzf_defc "$cmd" _fzf_dir_completion "-o nospace -o dirnames"348done349[completion] Make kill completion more consistent with the othersJunegunn Choibefore adoptionc329279
line 350why, one step back350# Kill completion (supports empty completion trigger)[bash-completion] Fix default alias/variable completionJunegunn Choibefore adoptiond4ad4a2
line 351why, one step back351complete -F _fzf_complete_kill -o default -o bashdefault kill[zsh] Prevent the current directory from appearing as `~dir` in prompts (#1774)midchildanbefore adoptionf51d61d
line 352why, one step back352Remove dead codeJunegunn Choibefore adoption6e464eb
line 353why, one step back353unset cmd d_cmds a_cmds[zsh] Prevent the current directory from appearing as `~dir` in prompts (#1774)midchildanbefore adoptionf51d61d
lines 354–359why, one step back354355_fzf_setup_completion() {356 local kind fn cmd357 kind=$1358 fn=_fzf_${1}_completion359 if [[ $# -lt 2 ]] || ! type -t "$fn" > /dev/null; then[completion] Make kill completion more consistent with the othersJunegunn Choibefore adoptionc329279
line 360why, one step back360 echo "usage: ${FUNCNAME[0]} path|dir|var|alias|host|proc COMMANDS..."[zsh] Prevent the current directory from appearing as `~dir` in prompts (#1774)midchildanbefore adoptionf51d61d
lines 361–363why, one step back361 return 1362 fi363 shift[bash-completion] Optimize __fzf_orig_completion_filterTomas Janousekbefore adoptionef2c29d
line 364why, one step back364 __fzf_orig_completion < <(complete -p "$@" 2> /dev/null)[zsh] Prevent the current directory from appearing as `~dir` in prompts (#1774)midchildanbefore adoptionf51d61d
lines 365–366why, one step back365 for cmd in "$@"; do366 case "$kind" in[bash-completion] Fix default alias/variable completionJunegunn Choibefore adoptiond4ad4a2
lines 367–370why, one step back367 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" ;;[zsh] Prevent the current directory from appearing as `~dir` in prompts (#1774)midchildanbefore adoptionf51d61d
lines 371–373why, one step back371 esac372 done373}[bash-completion] Fix default alias/variable completionJunegunn Choibefore adoptiond4ad4a2
lines 374–378why, one step back374375# Environment variables / Aliases / Hosts376_fzf_setup_completion 'var' export unset377_fzf_setup_completion 'alias' unalias378_fzf_setup_completion 'host' ssh telnet[zsh] Prevent the current directory from appearing as `~dir` in prompts (#1774)midchildanbefore adoptionf51d61d
lines 379–380why, one step back379380fi