Skip to content
Myr

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 file

Take 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 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)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###########################################################33

make lint: Perform bash script lintingJunegunn Choibefore adoptionf0c4ee4

line 34why, one step back
34#----BEGIN shfmt

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 35–36why, one step back
35#----BEGIN INCLUDE common.sh
36# 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 back
37# To modify it, one can edit "common.sh" and run "./update.sh" to apply

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 38–40why, one step back
38# 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 back
41 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 back
42 command cat "${FZF_DEFAULT_OPTS_FILE-}" 2> /dev/null

Replace printf with builtin printf to by pass local indirections (#4684)Darren Bishopbefore adoption4866c34

line 43why, one step back
43 builtin printf '%s\n' "${FZF_DEFAULT_OPTS-} $2"

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 44–50why, one step back
44}
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/awk

Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315

line 51why, one step back
51 elif command -v mawk > /dev/null 2>&1; then

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

line 52why, one step back
52 local n x y z d

fix(shell): check for mawk existence before version check (#4468)LangLangBartbefore adoption354d046

line 53why, one step back
53 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 back
54 [[ $n == mawk ]] &&
55 (((x * 1000 + y) * 1000 + z >= 1003004)) 2> /dev/null &&56 ((d >= 20230302)) 2> /dev/null &&57 __fzf_awk=mawk

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 58–64why, one step back
58 fi
59 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 back
65 if [[ "$(type -t _fzf_comprun 2>&1)" == function ]]; then

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

line 66why, one step back
66 _fzf_comprun "$@"

Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315

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

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 68–78why, one step back
68 shift
69 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; do

Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315

line 79why, one step back
79 if [[ $l =~ ^(.*\ -F)\ *([^ ]*).*\ ([^ ]*)$ ]]; then

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 80–82why, one step back
80 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 back
83 [[ $f == _fzf_* ]] && continue

Replace printf with builtin printf to by pass local indirections (#4684)Darren Bishopbefore adoption4866c34

line 84why, one step back
84 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 back
85 if [[ $l == *" -o nospace "* ]] && [[ ${__fzf_nospace_commands-} != *" $cmd "* ]]; then

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 86–113why, one step back
86 __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 1

Replace printf with builtin printf to by pass local indirections (#4684)Darren Bishopbefore adoption4866c34

line 114why, one step back
114 builtin printf -v REPLY "$orig" "$func"

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 115–120why, one step back
115}
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 back
121 prev="${COMP_WORDS[COMP_CWORD - 1]}"

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 122–126why, one step back
122 opts="
123 +c --no-color124 +i --no-ignore-case125 +s --no-sort126 +x --no-extended

Update bash fzf option completionJunegunn Choibefore adoption111a62f

line 127why, one step back
127 --accept-nth

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 128–140why, one step back
128 --ansi
129 --bash130 --bind131 --border132 --border-label133 --border-label-pos134 --color135 --cycle136 --disabled137 --ellipsis138 --expect139 --filepath-word140 --fish

Update bash fzf option completionJunegunn Choibefore adoption111a62f

lines 141–151why, one step back
141 --footer
142 --footer-border143 --footer-label144 --footer-label-pos145 --freeze-left146 --freeze-right147 --gap148 --gap-line149 --ghost150 --gutter151 --gutter-raw

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

line 152why, one step back
152 --header

Update bash fzf option completionJunegunn Choibefore adoption111a62f

line 153why, one step back
153 --header-border

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

line 154why, one step back
154 --header-first

Update bash fzf option completionJunegunn Choibefore adoption111a62f

lines 155–156why, one step back
155 --header-label
156 --header-label-pos

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

line 157why, one step back
157 --header-lines

Update bash fzf option completionJunegunn Choibefore adoption111a62f

line 158why, one step back
158 --header-lines-border

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 159–164why, one step back
159 --height
160 --highlight-line161 --history162 --history-size163 --hscroll-off164 --info

Update bash fzf option completionJunegunn Choibefore adoption111a62f

lines 165–168why, one step back
165 --info-command
166 --input-border167 --input-label168 --input-label-pos

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 169–173why, one step back
169 --jump-labels
170 --keep-right171 --layout172 --listen173 --listen-unsafe

Update bash fzf option completionJunegunn Choibefore adoption111a62f

lines 174–176why, one step back
174 --list-border
175 --list-label176 --list-label-pos

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 177–180why, one step back
177 --literal
178 --man179 --margin180 --marker

Update bash fzf option completionJunegunn Choibefore adoption111a62f

line 181why, one step back
181 --marker-multi-line

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 182–184why, one step back
182 --min-height
183 --no-bold184 --no-hscroll

Update bash fzf option completionJunegunn Choibefore adoption111a62f

lines 185–186why, one step back
185 --no-input
186 --no-multi-line

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 187–191why, one step back
187 --no-scrollbar
188 --no-separator189 --padding190 --pointer191 --preview

Update bash fzf option completionJunegunn Choibefore adoption111a62f

line 192why, one step back
192 --preview-border

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 193–198why, one step back
193 --preview-label
194 --preview-label-pos195 --preview-window196 --print-query197 --print0198 --prompt

Update bash fzf option completionJunegunn Choibefore adoption111a62f

line 199why, one step back
199 --raw

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 200–202why, one step back
200 --read0
201 --scheme202 --scroll-off

Update bash fzf option completionJunegunn Choibefore adoption111a62f

line 203why, one step back
203 --scrollbar

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

line 204why, one step back
204 --separator

Update bash fzf option completionJunegunn Choibefore adoption111a62f

lines 205–206why, one step back
205 --smart-case
206 --style

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 207–209why, one step back
207 --sync
208 --tabstop209 --tac

Update bash fzf option completionJunegunn Choibefore adoption111a62f

line 210why, one step back
210 --tail

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 211–214why, one step back
211 --tiebreak
212 --tmux213 --track214 --version

Update bash fzf option completionJunegunn Choibefore adoption111a62f

lines 215–217why, one step back
215 --walker
216 --walker-root217 --walker-skip

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 218–220why, one step back
218 --with-nth
219 --with-shell220 --wrap

Update bash fzf option completionJunegunn Choibefore adoption111a62f

line 221why, one step back
221 --wrap-sign

Add --preview-wrap-signJunegunn Choibefore adoption4a195e6

line 222why, one step back
222 --preview-wrap-sign

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 223–236why, one step back
223 --zsh
224 -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}" in

Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315

lines 237–241why, one step back
237 --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 back
242 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 back
243 return 0
244 ;;245 --color)

Update bash fzf option completionJunegunn Choibefore adoption111a62f

line 246why, one step back
246 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 back
247 return 0
248 ;;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 back
257 --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 back
265 --preview-window)
266 COMPREPLY=($(compgen -W "

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 267–270why, one step back
267 default
268 hidden269 nohidden270 wrap

Update bash fzf option completionJunegunn Choibefore adoption111a62f

line 271why, one step back
271 wrap-word

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 272–279why, one step back
272 nowrap
273 cycle274 nocycle275 up top276 down bottom277 left278 right279 rounded border border-rounded

Update bash fzf option completionJunegunn Choibefore adoption111a62f

line 280why, one step back
280 border-line

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 281–293why, one step back
281 sharp border-sharp
282 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 follow

Update bash fzf option completionJunegunn Choibefore adoption111a62f

lines 294–296why, one step back
294 nofollow
295 info296 noinfo" -- "$cur"))

Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315

lines 297–298why, one step back
297 return 0
298 ;;

Update bash fzf option completionJunegunn Choibefore adoption111a62f

lines 299–300why, one step back
299 --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 back
301 return 0
302 ;;

Update bash fzf option completionJunegunn Choibefore adoption111a62f

line 303why, one step back
303 --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 back
304 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 back
307 esac
308

Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315

lines 309–310why, one step back
309 if [[ $cur =~ ^-|\+ ]]; then
310 COMPREPLY=($(compgen -W "${opts}" -- "$cur"))

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 311–323why, one step back
311 return 0
312 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 back
324 elif [[ -n ${_fzf_completion_loader-} ]]; then

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 325–337why, one step back
325 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=$REPLY337

Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315

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

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 339–357why, one step back
339 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 back
358 if [[ $cur == *"$trigger" ]] && [[ $cur != *'$('* ]] && [[ $cur != *':='* ]] && [[ $cur != *'`'* ]]; then

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 359–362why, one step back
359 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 back
363 [[ $base == *"/"* ]] && dir="$base"

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

line 364why, one step back
364 while true; do

Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315

lines 365–369why, one step back
365 if [[ -z $dir ]] || [[ -d $dir ]]; then
366 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 back
370 matches=$(
371 export FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse --scheme=path" "${FZF_COMPLETION_OPTS-} $2")372 unset FZF_DEFAULT_COMMAND FZF_DEFAULT_OPTS_FILE

Fix FZF_COMPLETION_{DIR,PATH}_OPTS ignored with custom compgen functions (#4679)Kyle Tsebefore adoption1a50a3c

lines 373–377why, one step back
373 if [[ $1 =~ dir ]]; then
374 eval "rest=(${FZF_COMPLETION_DIR_OPTS-})"375 else376 eval "rest=(${FZF_COMPLETION_PATH_OPTS-})"377 fi

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

line 378why, one step back
378 if declare -F "$1" > /dev/null; then

Replace printf with builtin printf to by pass local indirections (#4684)Darren Bishopbefore adoption4866c34

line 379why, one step back
379 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 back
380 else
381 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; do

Replace printf with builtin printf to by pass local indirections (#4684)Darren Bishopbefore adoption4866c34

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

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 389–391why, one step back
389 done
390 )391 matches=${matches% }

Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315

lines 392–394why, one step back
392 [[ -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 back
395 else

Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315

line 396why, one step back
396 COMPREPLY=("$cur")

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

line 397why, one step back
397 fi

Replace printf with builtin printf to by pass local indirections (#4684)Darren Bishopbefore adoption4866c34

line 398why, one step back
398 # 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 back
399 bind '"\e[0n": redraw-current-line' 2> /dev/null

Replace printf with builtin printf to by pass local indirections (#4684)Darren Bishopbefore adoption4866c34

line 400why, one step back
400 builtin printf '\e[5n'

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 401–403why, one step back
401 return 0
402 fi403 dir=$(command dirname "$dir")

Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315

line 404why, one step back
404 [[ $dir =~ /$ ]] || dir="$dir"/

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 405–419why, one step back
405 done
406 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[@]}"; do

Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315

line 420why, one step back
420 if [[ ${args[$i]} == -- ]]; then

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 421–424why, one step back
421 sep=$i
422 break423 fi424 done

Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315

line 425why, one step back
425 if [[ -n $sep ]]; then

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 426–427why, one step back
426 str_arg=
427 rest=("${args[@]:$((sep + 1)):${#args[@]}}")

Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315

line 428why, one step back
428 args=("${args[@]:0:sep}")

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 429–442why, one step back
429 else
430 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 back
443 if [[ $cur == *"$trigger" ]] && [[ $cur != *'$('* ]] && [[ $cur != *':='* ]] && [[ $cur != *'`'* ]]; then

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 444–448why, one step back
444 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 back
449 __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 back
451 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 back
452 if [[ -n $selected ]]; then

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 453–457why, one step back
453 COMPREPLY=("$selected")
454 else455 COMPREPLY=("$cur")456 fi457 bind '"\e[0n": redraw-current-line' 2> /dev/null

Replace printf with builtin printf to by pass local indirections (#4684)Darren Bishopbefore adoption4866c34

line 458why, one step back
458 builtin printf '\e[5n'

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 459–509why, one step back
459 return 0
460 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 back
510 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 back
514}
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 back
530# builtin printf '%s\n' "${COMPREPLY[@]}" | command sort -u --version-sort

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 531–579why, one step back
531# }
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 back
580 ' /etc/hosts 2> /dev/null

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 581–595why, one step back
581 )
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 in

Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315

line 596why, one step back
596 -i | -F | -E)

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 597–600why, one step back
597 _fzf_path_completion "$@"
598 ;;599 *)600 local user=

Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315

line 601why, one step back
601 [[ $2 =~ '@' ]] && user="${2%%@*}@"

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 602–731why, one step back
602 _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" in

Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315

lines 732–733why, one step back
732 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 back
734 alias) __fzf_defc "$cmd" "$fn" "-a" ;;

Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315

line 735why, one step back
735 *) __fzf_defc "$cmd" "$fn" "-o default -o bashdefault" ;;

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 736–738why, one step back
736 esac
737 done738}

make lint: Perform bash script lintingJunegunn Choibefore adoptionf0c4ee4

line 739why, one step back
739#----END shfmt

Explain the need to escape placeholders in transform actionsJunegunn Choibefore adoption976001e

lines 740–741why, one step back
740
741fi