Skip to content
Myr

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

Before adoption: this commit came in with the history the project adopted, so no landing records it.

On macos, having run `brew install coreutils`, which installed GNU version of `printf`, this script/completion would sometimes complain about the (now missing) `-v` option usage. This change set ensures the `-v` option is available where needed.

authored by Darren Bishop · committed by GitHub · parent 3cfee28 · Browse files · 1 file+10 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Note: there is a precedent of qualify which tool to run e.g. `command find ...`, `command dirname ...`, etc, so hopefully `builtin printf ...` should not cause any offense.

Diff stats

1 file+10 added−10 removed

  • other:+10 added−10 removed

1 file+10 added−10 removed

modified:shell/completion.bash+10 added-10 removed
36 unmodified lines
37# To modify it, one can edit "common.sh" and run "./update.sh" to apply38# the changes. See code comments in "common.sh" for the implementation details.3940__fzf_defaults() {41 printf '%s\n' "--height ${FZF_TMUX_HEIGHT:-40%} --min-height 20+ --bind=ctrl-z:ignore $1"41 builtin printf '%s\n' "--height ${FZF_TMUX_HEIGHT:-40%} --min-height 20+ --bind=ctrl-z:ignore $1"42 command cat "${FZF_DEFAULT_OPTS_FILE-}" 2> /dev/null43 printf '%s\n' "${FZF_DEFAULT_OPTS-} $2"43 builtin printf '%s\n' "${FZF_DEFAULT_OPTS-} $2"44}4546__fzf_exec_awk() {47 if [[ -z ${__fzf_awk-} ]]; then
32 unmodified lines
80 comp="${BASH_REMATCH[1]}"81 f="${BASH_REMATCH[2]}"82 cmd="${BASH_REMATCH[3]}"83 [[ $f == _fzf_* ]] && continue84 printf -v "_fzf_orig_completion_${cmd//[^A-Za-z0-9_]/_}" "%s" "${comp} %s ${cmd} #${f}"84 builtin printf -v "_fzf_orig_completion_${cmd//[^A-Za-z0-9_]/_}" "%s" "${comp} %s ${cmd} #${f}"85 if [[ $l == *" -o nospace "* ]] && [[ ${__fzf_nospace_commands-} != *" $cmd "* ]]; then86 __fzf_nospace_commands="${__fzf_nospace_commands-} $cmd "87 fi88 fi
21 unmodified lines
110 orig_var="_fzf_orig_completion_${cmd//[^A-Za-z0-9_]/_}"111 orig="${!orig_var-}"112 orig="${orig%#*}"113 [[ $orig == *' %s '* ]] || return 1114 printf -v REPLY "$orig" "$func"114 builtin printf -v REPLY "$orig" "$func"115}116117_fzf_opts_completion() {118 local cur prev opts
256 unmodified lines
375 else376 eval "rest=(${FZF_COMPLETION_PATH_OPTS-})"377 fi378 if declare -F "$1" > /dev/null; then379 eval "$1 $(printf %q "$dir")" | __fzf_comprun "$4" -q "$leftover" "${rest[@]}"379 eval "$1 $(builtin printf %q "$dir")" | __fzf_comprun "$4" -q "$leftover" "${rest[@]}"380 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; do388 printf "%q " "${item%$3}$3"388 builtin printf "%q " "${item%$3}$3"389 done390 )391 matches=${matches% }392 [[ -z $3 ]] && [[ ${__fzf_nospace_commands-} == *" ${COMP_WORDS[0]} "* ]] && matches="$matches "
1 unmodified line
394 COMPREPLY=("$matches")395 else396 COMPREPLY=("$cur")397 fi398 # To redraw line after fzf closes (printf '\e[5n')398 # To redraw line after fzf closes (builtin printf '\e[5n')399 bind '"\e[0n": redraw-current-line' 2> /dev/null400 printf '\e[5n'400 builtin printf '\e[5n'401 return 0402 fi403 dir=$(command dirname "$dir")404 [[ $dir =~ /$ ]] || dir="$dir"/
49 unmodified lines
454 else455 COMPREPLY=("$cur")456 fi457 bind '"\e[0n": redraw-current-line' 2> /dev/null458 printf '\e[5n'458 builtin printf '\e[5n'459 return 0460 else461 _fzf_handle_dynamic_completion "$cmd" "${rest[@]}"462 fi
63 unmodified lines
526# __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 ''530# printf '%s\n' "${COMPREPLY[@]}" | command sort -u --version-sort530# builtin printf '%s\n' "${COMPREPLY[@]}" | command sort -u --version-sort531# }532if ! declare -F __fzf_list_hosts > /dev/null; then533 __fzf_list_hosts() {534 command sort -u \
207 unmodified lines