completion.bash
This file
Path
shell/completion.bash
741 lines · 21.2 KiB · Shell
Last changed by
Replace printf with builtin printf to by pass local indirections (#4684)Darren Bishopbefore adoption4866c34
History of this fileTake it
The walk stopped after 200 commits: lines older than 976001e point at it.
Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 1–33why, one step back1# ____ ____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)11# - $FZF_COMPLETION_PATH_OPTS (default: empty)12# - $FZF_COMPLETION_DIR_OPTS (default: empty)1314if [[ $- =~ i ]]; then151617# To use custom commands instead of find, override _fzf_compgen_{path,dir}18#19# _fzf_compgen_path() {20# echo "$1"21# command find -L "$1" \22# -name .git -prune -o -name .hg -prune -o -name .svn -prune -o \( -type d -o -type f -o -type l \) \23# -a -not -path "$1" -print 2> /dev/null | command sed 's@^\./@@'24# }25#26# _fzf_compgen_dir() {27# command find -L "$1" \28# -name .git -prune -o -name .hg -prune -o -name .svn -prune -o -type d \29# -a -not -path "$1" -print 2> /dev/null | command sed 's@^\./@@'30# }3132###########################################################33make lint: Perform bash script lintingJunegunn Choibefore adoptionf0c4ee4
line 34why, one step back34#----BEGIN shfmtExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 35–36why, one step back35#----BEGIN INCLUDE common.sh36# NOTE: Do not directly edit this section, which is copied from "common.sh".make lint: Perform bash script lintingJunegunn Choibefore adoptionf0c4ee4
line 37why, one step back37# To modify it, one can edit "common.sh" and run "./update.sh" to applyExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 38–40why, one step back38# the changes. See code comments in "common.sh" for the implementation details.3940__fzf_defaults() {Replace printf with builtin printf to by pass local indirections (#4684)Darren Bishopbefore adoption4866c34
line 41why, one step back41 builtin printf '%s\n' "--height ${FZF_TMUX_HEIGHT:-40%} --min-height 20+ --bind=ctrl-z:ignore $1"Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
line 42why, one step back42 command cat "${FZF_DEFAULT_OPTS_FILE-}" 2> /dev/nullReplace printf with builtin printf to by pass local indirections (#4684)Darren Bishopbefore adoption4866c34
line 43why, one step back43 builtin printf '%s\n' "${FZF_DEFAULT_OPTS-} $2"Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 44–50why, one step back44}4546__fzf_exec_awk() {47 if [[ -z ${__fzf_awk-} ]]; then48 __fzf_awk=awk49 if [[ $OSTYPE == solaris* && -x /usr/xpg4/bin/awk ]]; then50 __fzf_awk=/usr/xpg4/bin/awkApply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
line 51why, one step back51 elif command -v mawk > /dev/null 2>&1; thenExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
line 52why, one step back52 local n x y z dfix(shell): check for mawk existence before version check (#4468)LangLangBartbefore adoption354d046
line 53why, one step back53 IFS=' .' read -r n x y z d <<< $(command mawk -W version 2> /dev/null)[bash,zsh] Fix the version check for mawk (#4574)Koichi Murasebefore adoption5cb6957
lines 54–57why, one step back54 [[ $n == mawk ]] &&55 (((x * 1000 + y) * 1000 + z >= 1003004)) 2> /dev/null &&56 ((d >= 20230302)) 2> /dev/null &&57 __fzf_awk=mawkExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 58–64why, one step back58 fi59 fi60 LC_ALL=C exec "$__fzf_awk" "$@"61}62#----END INCLUDE6364__fzf_comprun() {Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
line 65why, one step back65 if [[ "$(type -t _fzf_comprun 2>&1)" == function ]]; thenExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
line 66why, one step back66 _fzf_comprun "$@"Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
line 67why, one step back67 elif [[ -n ${TMUX_PANE-} ]] && { [[ ${FZF_TMUX:-0} != 0 ]] || [[ -n ${FZF_TMUX_OPTS-} ]]; }; thenExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 68–78why, one step back68 shift69 fzf-tmux ${FZF_TMUX_OPTS:--d${FZF_TMUX_HEIGHT:-40%}} -- "$@"70 else71 shift72 fzf "$@"73 fi74}7576__fzf_orig_completion() {77 local l comp f cmd78 while read -r l; doApply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
line 79why, one step back79 if [[ $l =~ ^(.*\ -F)\ *([^ ]*).*\ ([^ ]*)$ ]]; thenExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 80–82why, one step back80 comp="${BASH_REMATCH[1]}"81 f="${BASH_REMATCH[2]}"82 cmd="${BASH_REMATCH[3]}"Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
line 83why, one step back83 [[ $f == _fzf_* ]] && continueReplace printf with builtin printf to by pass local indirections (#4684)Darren Bishopbefore adoption4866c34
line 84why, one step back84 builtin printf -v "_fzf_orig_completion_${cmd//[^A-Za-z0-9_]/_}" "%s" "${comp} %s ${cmd} #${f}"Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
line 85why, one step back85 if [[ $l == *" -o nospace "* ]] && [[ ${__fzf_nospace_commands-} != *" $cmd "* ]]; thenExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 86–113why, one step back86 __fzf_nospace_commands="${__fzf_nospace_commands-} $cmd "87 fi88 fi89 done90}9192# @param $1 cmd - Command name for which the original completion is searched93# @var[out] REPLY - Original function name is returned94__fzf_orig_completion_get_orig_func() {95 local cmd orig_var orig96 cmd=$197 orig_var="_fzf_orig_completion_${cmd//[^A-Za-z0-9_]/_}"98 orig="${!orig_var-}"99 REPLY="${orig##*#}"100 [[ $REPLY ]] && type "$REPLY" &> /dev/null101}102103# @param $1 cmd - Command name for which the original completion is searched104# @param $2 func - Fzf's completion function to replace the original function105# @var[out] REPLY - Completion setting is returned as a string to "eval"106__fzf_orig_completion_instantiate() {107 local cmd func orig_var orig108 cmd=$1109 func=$2110 orig_var="_fzf_orig_completion_${cmd//[^A-Za-z0-9_]/_}"111 orig="${!orig_var-}"112 orig="${orig%#*}"113 [[ $orig == *' %s '* ]] || return 1Replace printf with builtin printf to by pass local indirections (#4684)Darren Bishopbefore adoption4866c34
line 114why, one step back114 builtin printf -v REPLY "$orig" "$func"Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 115–120why, one step back115}116117_fzf_opts_completion() {118 local cur prev opts119 COMPREPLY=()120 cur="${COMP_WORDS[COMP_CWORD]}"Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
line 121why, one step back121 prev="${COMP_WORDS[COMP_CWORD - 1]}"Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 122–126why, one step back122 opts="123 +c --no-color124 +i --no-ignore-case125 +s --no-sort126 +x --no-extendedUpdate bash fzf option completionJunegunn Choibefore adoption111a62f
line 127why, one step back127 --accept-nthExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 128–140why, one step back128 --ansi129 --bash130 --bind131 --border132 --border-label133 --border-label-pos134 --color135 --cycle136 --disabled137 --ellipsis138 --expect139 --filepath-word140 --fishUpdate bash fzf option completionJunegunn Choibefore adoption111a62f
lines 141–151why, one step back141 --footer142 --footer-border143 --footer-label144 --footer-label-pos145 --freeze-left146 --freeze-right147 --gap148 --gap-line149 --ghost150 --gutter151 --gutter-rawExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
line 152why, one step back152 --headerUpdate bash fzf option completionJunegunn Choibefore adoption111a62f
line 153why, one step back153 --header-borderExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
line 154why, one step back154 --header-firstUpdate bash fzf option completionJunegunn Choibefore adoption111a62f
lines 155–156why, one step back155 --header-label156 --header-label-posExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
line 157why, one step back157 --header-linesUpdate bash fzf option completionJunegunn Choibefore adoption111a62f
line 158why, one step back158 --header-lines-borderExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 159–164why, one step back159 --height160 --highlight-line161 --history162 --history-size163 --hscroll-off164 --infoUpdate bash fzf option completionJunegunn Choibefore adoption111a62f
lines 165–168why, one step back165 --info-command166 --input-border167 --input-label168 --input-label-posExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 169–173why, one step back169 --jump-labels170 --keep-right171 --layout172 --listen173 --listen-unsafeUpdate bash fzf option completionJunegunn Choibefore adoption111a62f
lines 174–176why, one step back174 --list-border175 --list-label176 --list-label-posExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 177–180why, one step back177 --literal178 --man179 --margin180 --markerUpdate bash fzf option completionJunegunn Choibefore adoption111a62f
line 181why, one step back181 --marker-multi-lineExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 182–184why, one step back182 --min-height183 --no-bold184 --no-hscrollUpdate bash fzf option completionJunegunn Choibefore adoption111a62f
lines 185–186why, one step back185 --no-input186 --no-multi-lineExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 187–191why, one step back187 --no-scrollbar188 --no-separator189 --padding190 --pointer191 --previewUpdate bash fzf option completionJunegunn Choibefore adoption111a62f
line 192why, one step back192 --preview-borderExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 193–198why, one step back193 --preview-label194 --preview-label-pos195 --preview-window196 --print-query197 --print0198 --promptUpdate bash fzf option completionJunegunn Choibefore adoption111a62f
line 199why, one step back199 --rawExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 200–202why, one step back200 --read0201 --scheme202 --scroll-offUpdate bash fzf option completionJunegunn Choibefore adoption111a62f
line 203why, one step back203 --scrollbarExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
line 204why, one step back204 --separatorUpdate bash fzf option completionJunegunn Choibefore adoption111a62f
lines 205–206why, one step back205 --smart-case206 --styleExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 207–209why, one step back207 --sync208 --tabstop209 --tacUpdate bash fzf option completionJunegunn Choibefore adoption111a62f
line 210why, one step back210 --tailExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 211–214why, one step back211 --tiebreak212 --tmux213 --track214 --versionUpdate bash fzf option completionJunegunn Choibefore adoption111a62f
lines 215–217why, one step back215 --walker216 --walker-root217 --walker-skipExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 218–220why, one step back218 --with-nth219 --with-shell220 --wrapUpdate bash fzf option completionJunegunn Choibefore adoption111a62f
line 221why, one step back221 --wrap-signAdd --preview-wrap-signJunegunn Choibefore adoption4a195e6
line 222why, one step back222 --preview-wrap-signExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 223–236why, one step back223 --zsh224 -0 --exit-0225 -1 --select-1226 -d --delimiter227 -e --exact228 -f --filter229 -h --help230 -i --ignore-case231 -m --multi232 -n --nth233 -q --query234 --"235236 case "${prev}" inApply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
lines 237–241why, one step back237 --scheme)238 COMPREPLY=($(compgen -W "default path history" -- "$cur"))239 return 0240 ;;241 --tiebreak)Update bash fzf option completionJunegunn Choibefore adoption111a62f
line 242why, one step back242 COMPREPLY=($(compgen -W "length chunk pathname begin end index" -- "$cur"))Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
lines 243–245why, one step back243 return 0244 ;;245 --color)Update bash fzf option completionJunegunn Choibefore adoption111a62f
line 246why, one step back246 COMPREPLY=($(compgen -W "dark light base16 16 bw no" -- "$cur"))Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
lines 247–256why, one step back247 return 0248 ;;249 --layout)250 COMPREPLY=($(compgen -W "default reverse reverse-list" -- "$cur"))251 return 0252 ;;253 --info)254 COMPREPLY=($(compgen -W "default right hidden inline inline-right" -- "$cur"))255 return 0256 ;;Update bash fzf option completionJunegunn Choibefore adoption111a62f
lines 257–264why, one step back257 --wrap)258 COMPREPLY=($(compgen -W "char word" -- "$cur"))259 return 0260 ;;261 --style)262 COMPREPLY=($(compgen -W "default minimal full" -- "$cur"))263 return 0264 ;;Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
lines 265–266why, one step back265 --preview-window)266 COMPREPLY=($(compgen -W "Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 267–270why, one step back267 default268 hidden269 nohidden270 wrapUpdate bash fzf option completionJunegunn Choibefore adoption111a62f
line 271why, one step back271 wrap-wordExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 272–279why, one step back272 nowrap273 cycle274 nocycle275 up top276 down bottom277 left278 right279 rounded border border-roundedUpdate bash fzf option completionJunegunn Choibefore adoption111a62f
line 280why, one step back280 border-lineExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 281–293why, one step back281 sharp border-sharp282 border-bold283 border-block284 border-thinblock285 border-double286 noborder border-none287 border-horizontal288 border-vertical289 border-up border-top290 border-down border-bottom291 border-left292 border-right293 followUpdate bash fzf option completionJunegunn Choibefore adoption111a62f
lines 294–296why, one step back294 nofollow295 info296 noinfo" -- "$cur"))Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
lines 297–298why, one step back297 return 0298 ;;Update bash fzf option completionJunegunn Choibefore adoption111a62f
lines 299–300why, one step back299 --border | --list-border | --header-border | --header-lines-border | --footer-border | --input-border | --preview-border)300 COMPREPLY=($(compgen -W "line rounded sharp bold block thinblock double horizontal vertical top bottom left right none" -- "$cur"))Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
lines 301–302why, one step back301 return 0302 ;;Update bash fzf option completionJunegunn Choibefore adoption111a62f
line 303why, one step back303 --border-label-pos | --preview-label-pos | --list-label-pos | --header-label-pos | --footer-label-pos | --input-label-pos)Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
lines 304–306why, one step back304 COMPREPLY=($(compgen -W "center bottom top" -- "$cur"))305 return 0306 ;;Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 307–308why, one step back307 esac308Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
lines 309–310why, one step back309 if [[ $cur =~ ^-|\+ ]]; then310 COMPREPLY=($(compgen -W "${opts}" -- "$cur"))Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 311–323why, one step back311 return 0312 fi313314 return 0315}316317_fzf_handle_dynamic_completion() {318 local cmd ret REPLY orig_cmd orig_complete319 cmd="$1"320 shift321 orig_cmd="$1"322 if __fzf_orig_completion_get_orig_func "$cmd"; then323 "$REPLY" "$@"Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
line 324why, one step back324 elif [[ -n ${_fzf_completion_loader-} ]]; thenExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 325–337why, one step back325 orig_complete=$(complete -p "$orig_cmd" 2> /dev/null)326 $_fzf_completion_loader "$@"327 ret=$?328 # _completion_loader may not have updated completion for the command329 if [[ "$(complete -p "$orig_cmd" 2> /dev/null)" != "$orig_complete" ]]; then330 __fzf_orig_completion < <(complete -p "$orig_cmd" 2> /dev/null)331 __fzf_orig_completion_get_orig_func "$cmd" || ret=1332333 # Update orig_complete by _fzf_orig_completion entry334 [[ $orig_complete =~ ' -F '(_fzf_[^ ]+)' ' ]] &&335 __fzf_orig_completion_instantiate "$cmd" "${BASH_REMATCH[1]}" &&336 orig_complete=$REPLY337Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
line 338why, one step back338 if [[ ${__fzf_nospace_commands-} == *" $orig_cmd "* ]]; thenExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 339–357why, one step back339 eval "${orig_complete/ -F / -o nospace -F }"340 else341 eval "$orig_complete"342 fi343 fi344 [[ $ret -eq 0 ]] && return 124345 return $ret346 fi347}348349__fzf_generic_path_completion() {350 local cur base dir leftover matches trigger cmd351 cmd="${COMP_WORDS[0]}"352 if [[ $cmd == \\* ]]; then353 cmd="${cmd:1}"354 fi355 COMPREPLY=()356 trigger=${FZF_COMPLETION_TRIGGER-'**'}357 [[ $COMP_CWORD -ge 0 ]] && cur="${COMP_WORDS[COMP_CWORD]}"Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
line 358why, one step back358 if [[ $cur == *"$trigger" ]] && [[ $cur != *'$('* ]] && [[ $cur != *':='* ]] && [[ $cur != *'`'* ]]; thenExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 359–362why, one step back359 base=${cur:0:${#cur}-${#trigger}}360 eval "base=$base" 2> /dev/null || return361362 dir=Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
line 363why, one step back363 [[ $base == *"/"* ]] && dir="$base"Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
line 364why, one step back364 while true; doApply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
lines 365–369why, one step back365 if [[ -z $dir ]] || [[ -d $dir ]]; then366 leftover=${base/#"$dir"/}367 leftover=${leftover/#\//}368 [[ -z $dir ]] && dir='.'369 [[ $dir != "/" ]] && dir="${dir/%\//}"Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 370–372why, one step back370 matches=$(371 export FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse --scheme=path" "${FZF_COMPLETION_OPTS-} $2")372 unset FZF_DEFAULT_COMMAND FZF_DEFAULT_OPTS_FILEFix FZF_COMPLETION_{DIR,PATH}_OPTS ignored with custom compgen functions (#4679)Kyle Tsebefore adoption1a50a3c
lines 373–377why, one step back373 if [[ $1 =~ dir ]]; then374 eval "rest=(${FZF_COMPLETION_DIR_OPTS-})"375 else376 eval "rest=(${FZF_COMPLETION_PATH_OPTS-})"377 fiExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
line 378why, one step back378 if declare -F "$1" > /dev/null; thenReplace printf with builtin printf to by pass local indirections (#4684)Darren Bishopbefore adoption4866c34
line 379why, one step back379 eval "$1 $(builtin printf %q "$dir")" | __fzf_comprun "$4" -q "$leftover" "${rest[@]}"Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 380–387why, one step back380 else381 if [[ $1 =~ dir ]]; then382 walker=dir,follow383 else384 walker=file,dir,follow,hidden385 fi386 __fzf_comprun "$4" -q "$leftover" --walker "$walker" --walker-root="$dir" "${rest[@]}"387 fi | while read -r item; doReplace printf with builtin printf to by pass local indirections (#4684)Darren Bishopbefore adoption4866c34
line 388why, one step back388 builtin printf "%q " "${item%$3}$3"Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 389–391why, one step back389 done390 )391 matches=${matches% }Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
lines 392–394why, one step back392 [[ -z $3 ]] && [[ ${__fzf_nospace_commands-} == *" ${COMP_WORDS[0]} "* ]] && matches="$matches "393 if [[ -n $matches ]]; then394 COMPREPLY=("$matches")Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
line 395why, one step back395 elseApply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
line 396why, one step back396 COMPREPLY=("$cur")Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
line 397why, one step back397 fiReplace printf with builtin printf to by pass local indirections (#4684)Darren Bishopbefore adoption4866c34
line 398why, one step back398 # To redraw line after fzf closes (builtin printf '\e[5n')Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
line 399why, one step back399 bind '"\e[0n": redraw-current-line' 2> /dev/nullReplace printf with builtin printf to by pass local indirections (#4684)Darren Bishopbefore adoption4866c34
line 400why, one step back400 builtin printf '\e[5n'Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 401–403why, one step back401 return 0402 fi403 dir=$(command dirname "$dir")Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
line 404why, one step back404 [[ $dir =~ /$ ]] || dir="$dir"/Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 405–419why, one step back405 done406 else407 shift408 shift409 shift410 _fzf_handle_dynamic_completion "$cmd" "$@"411 fi412}413414_fzf_complete() {415 # Split arguments around --416 local args rest str_arg i sep417 args=("$@")418 sep=419 for i in "${!args[@]}"; doApply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
line 420why, one step back420 if [[ ${args[$i]} == -- ]]; thenExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 421–424why, one step back421 sep=$i422 break423 fi424 doneApply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
line 425why, one step back425 if [[ -n $sep ]]; thenExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 426–427why, one step back426 str_arg=427 rest=("${args[@]:$((sep + 1)):${#args[@]}}")Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
line 428why, one step back428 args=("${args[@]:0:sep}")Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 429–442why, one step back429 else430 str_arg=$1431 args=()432 shift433 rest=("$@")434 fi435436 local cur selected trigger cmd post437 post="$(caller 0 | __fzf_exec_awk '{print $2}')_post"438 type -t "$post" > /dev/null 2>&1 || post='command cat'439440 trigger=${FZF_COMPLETION_TRIGGER-'**'}441 cmd="${COMP_WORDS[0]}"442 cur="${COMP_WORDS[COMP_CWORD]}"Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
line 443why, one step back443 if [[ $cur == *"$trigger" ]] && [[ $cur != *'$('* ]] && [[ $cur != *':='* ]] && [[ $cur != *'`'* ]]; thenExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 444–448why, one step back444 cur=${cur:0:${#cur}-${#trigger}}445446 selected=$(447 FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse" "${FZF_COMPLETION_OPTS-} $str_arg") \448 FZF_DEFAULT_OPTS_FILE='' \Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
lines 449–450why, one step back449 __fzf_comprun "${rest[0]}" "${args[@]}" -q "$cur" | eval "$post" | command tr '\n' ' '450 )Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
line 451why, one step back451 selected=${selected% } # Strip trailing space not to repeat "-o nospace"Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
line 452why, one step back452 if [[ -n $selected ]]; thenExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 453–457why, one step back453 COMPREPLY=("$selected")454 else455 COMPREPLY=("$cur")456 fi457 bind '"\e[0n": redraw-current-line' 2> /dev/nullReplace printf with builtin printf to by pass local indirections (#4684)Darren Bishopbefore adoption4866c34
line 458why, one step back458 builtin printf '\e[5n'Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 459–509why, one step back459 return 0460 else461 _fzf_handle_dynamic_completion "$cmd" "${rest[@]}"462 fi463}464465_fzf_path_completion() {466 __fzf_generic_path_completion _fzf_compgen_path "-m" "" "$@"467}468469# Deprecated. No file only completion.470_fzf_file_completion() {471 _fzf_path_completion "$@"472}473474_fzf_dir_completion() {475 __fzf_generic_path_completion _fzf_compgen_dir "" "/" "$@"476}477478_fzf_complete_kill() {479 _fzf_proc_completion "$@"480}481482_fzf_proc_completion() {483 local transformer484 transformer='485 if [[ $FZF_KEY =~ ctrl|alt|shift ]] && [[ -n $FZF_NTH ]]; then486 nths=( ${FZF_NTH//,/ } )487 new_nths=()488 found=0489 for nth in ${nths[@]}; do490 if [[ $nth = $FZF_CLICK_HEADER_NTH ]]; then491 found=1492 else493 new_nths+=($nth)494 fi495 done496 [[ $found = 0 ]] && new_nths+=($FZF_CLICK_HEADER_NTH)497 new_nths=${new_nths[*]}498 new_nths=${new_nths// /,}499 echo "change-nth($new_nths)+change-prompt($new_nths> )"500 else501 if [[ $FZF_NTH = $FZF_CLICK_HEADER_NTH ]]; then502 echo "change-nth()+change-prompt(> )"503 else504 echo "change-nth($FZF_CLICK_HEADER_NTH)+change-prompt($FZF_CLICK_HEADER_WORD> )"505 fi506 fi507 '508 _fzf_complete -m --header-lines=1 --no-preview --wrap --color fg:dim,nth:regular \509 --bind "click-header:transform:$transformer" -- "$@" < <(Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
lines 510–513why, one step back510 command ps -eo user,pid,ppid,start,time,command 2> /dev/null ||511 command ps -eo user,pid,ppid,time,args 2> /dev/null || # For BusyBox512 command ps --everyone --full --windows # For cygwin513 )Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 514–529why, one step back514}515516_fzf_proc_completion_post() {517 __fzf_exec_awk '{print $2}'518}519520# To use custom hostname lists, override __fzf_list_hosts.521# The function is expected to print hostnames, one per line as well as in the522# desired sorting and with any duplicates removed, to standard output.523#524# e.g.525# # Use bash-completions’s _known_hosts_real() for getting the list of hosts526# __fzf_list_hosts() {527# # Set the local attribute for any non-local variable that is set by _known_hosts_real()528# local COMPREPLY=()529# _known_hosts_real ''Replace printf with builtin printf to by pass local indirections (#4684)Darren Bishopbefore adoption4866c34
line 530why, one step back530# builtin printf '%s\n' "${COMPREPLY[@]}" | command sort -u --version-sortExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 531–579why, one step back531# }532if ! declare -F __fzf_list_hosts > /dev/null; then533 __fzf_list_hosts() {534 command sort -u \535 <(536 # Note: To make the pathname expansion of "~/.ssh/config.d/*" work537 # properly, we need to adjust the related shell options. We need to538 # unset "set -f" and "GLOBIGNORE", which disable the pathname expansion539 # totally or partially. We need to unset "dotglob" and "nocaseglob" to540 # avoid matching unwanted files. We need to unset "failglob" to avoid541 # outputting the error messages to the terminal when no matching is542 # found. We need to set "nullglob" to avoid attempting to read the543 # literal filename '~/.ssh/config.d/*' when no matching is found.544 set +f545 GLOBIGNORE=546 shopt -u dotglob nocaseglob failglob547 shopt -s nullglob548549 __fzf_exec_awk '550 # Note: mawk <= 1.3.3-20090705 does not support the POSIX brackets of551 # the form [[:blank:]], and Ubuntu 18.04 LTS still uses this552 # 16-year-old mawk unfortunately. We need to use [ \t] instead.553 match(tolower($0), /^[ \t]*host(name)?[ \t]*[ \t=]/) {554 $0 = substr($0, RLENGTH + 1) # Remove "Host(name)?=?"555 sub(/#.*/, "")556 for (i = 1; i <= NF; i++)557 if ($i !~ /[*?%]/)558 print $i559 }560 ' ~/.ssh/config ~/.ssh/config.d/* /etc/ssh/ssh_config 2> /dev/null561 ) \562 <(563 __fzf_exec_awk -F ',' '564 match($0, /^[][a-zA-Z0-9.,:-]+/) {565 $0 = substr($0, 1, RLENGTH)566 gsub(/[][]|:[^,]*/, "")567 for (i = 1; i <= NF; i++)568 print $i569 }570 ' ~/.ssh/known_hosts 2> /dev/null571 ) \572 <(573 __fzf_exec_awk '574 {575 sub(/#.*/, "")576 for (i = 2; i <= NF; i++)577 if ($i != "0.0.0.0")578 print $i579 }fix(shell): check for mawk existence before version check (#4468)LangLangBartbefore adoption354d046
line 580why, one step back580 ' /etc/hosts 2> /dev/nullExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 581–595why, one step back581 )582 }583fi584585_fzf_host_completion() {586 _fzf_complete +m -- "$@" < <(__fzf_list_hosts)587}588589# Values for $1 $2 $3 are described here590# https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html591# > the first argument ($1) is the name of the command whose arguments are being completed,592# > the second argument ($2) is the word being completed,593# > and the third argument ($3) is the word preceding the word being completed on the current command line.594_fzf_complete_ssh() {595 case $3 inApply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
line 596why, one step back596 -i | -F | -E)Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 597–600why, one step back597 _fzf_path_completion "$@"598 ;;599 *)600 local user=Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
line 601why, one step back601 [[ $2 =~ '@' ]] && user="${2%%@*}@"Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 602–731why, one step back602 _fzf_complete +m -- "$@" < <(__fzf_list_hosts | __fzf_exec_awk -v user="$user" '{print user $0}')603 ;;604 esac605}606607_fzf_var_completion() {608 _fzf_complete -m -- "$@" < <(609 declare -xp | command sed -En 's|^declare [^ ]+ ([^=]+).*|\1|p'610 )611}612613_fzf_alias_completion() {614 _fzf_complete -m -- "$@" < <(615 alias | command sed -En 's|^alias ([^=]+).*|\1|p'616 )617}618619# fzf options620complete -o default -F _fzf_opts_completion fzf621# fzf-tmux is a thin fzf wrapper that has only a few more options than fzf622# itself. As a quick improvement we take fzf's completion. Adding the few extra623# fzf-tmux specific options (like `-w WIDTH`) are left as a future patch.624complete -o default -F _fzf_opts_completion fzf-tmux625626# Default path completion627__fzf_default_completion() {628 __fzf_generic_path_completion _fzf_compgen_path "-m" "" "$@"629630 # Dynamic completion loader has updated the completion for the command631 if [[ $? -eq 124 ]]; then632 # We trigger _fzf_setup_completion so that fuzzy completion for the command633 # still works. However, loader can update the completion for multiple634 # commands at once, and fuzzy completion will no longer work for those635 # other commands. e.g. pytest -> py.test, pytest-2, pytest-3, etc636 _fzf_setup_completion path "$1"637 return 124638 fi639}640641# Set fuzzy path completion as the default completion for all commands.642# We can't set up default completion,643# 1. if it's already set up by another script644# 2. or if the current version of bash doesn't support -D option645complete | command grep -q __fzf_default_completion ||646 complete | command grep -- '-D$' | command grep -qv _comp_complete_load ||647 complete -D -F __fzf_default_completion -o default -o bashdefault 2> /dev/null648649d_cmds="${FZF_COMPLETION_DIR_COMMANDS-cd pushd rmdir}"650651# NOTE: $FZF_COMPLETION_PATH_COMMANDS and $FZF_COMPLETION_VAR_COMMANDS are652# undocumented and subject to change in the future.653#654# NOTE: Although we have default completion, we still need to set up completion655# for each command in case they already have completion set up by another script.656a_cmds="${FZF_COMPLETION_PATH_COMMANDS-"657 awk bat cat code diff diff3658 emacs emacsclient ex file ftp g++ gcc gvim head hg hx java659 javac ld less more mvim nvim patch perl python ruby660 sed sftp sort source tail tee uniq vi view vim wc xdg-open661 basename bunzip2 bzip2 chmod chown curl cp dirname du662 find git grep gunzip gzip hg jar663 ln ls mv open rm rsync scp664 svn tar unzip zip"}"665v_cmds="${FZF_COMPLETION_VAR_COMMANDS-export unset printenv}"666667# Preserve existing completion668__fzf_orig_completion < <(complete -p $d_cmds $a_cmds $v_cmds unalias kill ssh 2> /dev/null)669670if type _comp_load > /dev/null 2>&1; then671 # _comp_load was added in bash-completion 2.12 to replace _completion_loader.672 # We use it without -D option so that it does not use _comp_complete_minimal as the fallback.673 _fzf_completion_loader=_comp_load674elif type __load_completion > /dev/null 2>&1; then675 # In bash-completion 2.11, _completion_loader internally calls __load_completion676 # and if it returns a non-zero status, it sets the default 'minimal' completion.677 _fzf_completion_loader=__load_completion678elif type _completion_loader > /dev/null 2>&1; then679 _fzf_completion_loader=_completion_loader680fi681682__fzf_defc() {683 local cmd func opts REPLY684 cmd="$1"685 func="$2"686 opts="$3"687 if __fzf_orig_completion_instantiate "$cmd" "$func"; then688 eval "$REPLY"689 else690 eval "complete -F \"$func\" $opts \"$cmd\""691 fi692}693694# Anything695for cmd in $a_cmds; do696 __fzf_defc "$cmd" _fzf_path_completion "-o default -o bashdefault"697done698699# Directory700for cmd in $d_cmds; do701 __fzf_defc "$cmd" _fzf_dir_completion "-o bashdefault -o nospace -o dirnames"702done703704# Variables705for cmd in $v_cmds; do706 __fzf_defc "$cmd" _fzf_var_completion "-o default -o nospace -v"707done708709# Aliases710__fzf_defc unalias _fzf_alias_completion "-a"711712# Processes713__fzf_defc kill _fzf_proc_completion "-o default -o bashdefault"714715# ssh716__fzf_defc ssh _fzf_complete_ssh "-o default -o bashdefault"717718unset cmd d_cmds a_cmds v_cmds719720_fzf_setup_completion() {721 local kind fn cmd722 kind=$1723 fn=_fzf_${1}_completion724 if [[ $# -lt 2 ]] || ! type -t "$fn" > /dev/null; then725 echo "usage: ${FUNCNAME[0]} path|dir|var|alias|host|proc COMMANDS..."726 return 1727 fi728 shift729 __fzf_orig_completion < <(complete -p "$@" 2> /dev/null)730 for cmd in "$@"; do731 case "$kind" inApply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
lines 732–733why, one step back732 dir) __fzf_defc "$cmd" "$fn" "-o nospace -o dirnames" ;;733 var) __fzf_defc "$cmd" "$fn" "-o default -o nospace -v" ;;Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
line 734why, one step back734 alias) __fzf_defc "$cmd" "$fn" "-a" ;;Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
line 735why, one step back735 *) __fzf_defc "$cmd" "$fn" "-o default -o bashdefault" ;;Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 736–738why, one step back736 esac737 done738}make lint: Perform bash script lintingJunegunn Choibefore adoptionf0c4ee4
line 739why, one step back739#----END shfmtExplain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e
lines 740–741why, one step back740741fi