Skip to content
Myr

[bash] Use `command` to “protect” further commands (#3462)

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

This commit causes all simple commands that are not built-ins or functions to be invoked via `command` in order to protect them from alias substitution or from accidentally taking functions of the same name. It was decided to not “protect” `fzf` and `fzf-tmux` for now. Maybe a better solution should be implemented for that in the future.

authored by Christoph Anton Mitterer · committed by GitHub · parent 404b6a8 · Browse files · 2 files+14 added−14 removed
This commit

State

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

Trailers

  • Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>

Diff stats

2 files+14 added−14 removed

  • other:+14 added−14 removed

2 files+14 added−14 removed

modified:shell/completion.bash+12 added-12 removed
16 unmodified lines
17 _fzf_compgen_path() {18 echo "$1"19 command find -L "$1" \20 -name .git -prune -o -name .hg -prune -o -name .svn -prune -o \( -type d -o -type f -o -type l \) \21 -a -not -path "$1" -print 2> /dev/null | sed 's@^\./@@'21 -a -not -path "$1" -print 2> /dev/null | command sed 's@^\./@@'22 }23fi2425if ! declare -F _fzf_compgen_dir > /dev/null; then26 _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 | sed 's@^\./@@'29 -a -not -path "$1" -print 2> /dev/null | command sed 's@^\./@@'30 }31fi3233###########################################################
287 unmodified lines
321 fi322 printf '\e[5n'323 return 0324 fi325 dir=$(dirname "$dir")325 dir=$(command dirname "$dir")326 [[ "$dir" =~ /$ ]] || dir="$dir"/327 done328 else329 shift
25 unmodified lines
355 rest=("$@")356 fi357358 local cur selected trigger cmd post359 post="$(caller 0 | awk '{print $2}')_post"360 type -t "$post" > /dev/null 2>&1 || post=cat359 post="$(caller 0 | command awk '{print $2}')_post"360 type -t "$post" > /dev/null 2>&1 || post='command cat'361362 cmd="${COMP_WORDS[0]//[^A-Za-z0-9_=]/_}"363 trigger=${FZF_COMPLETION_TRIGGER-'**'}364 cur="${COMP_WORDS[COMP_CWORD]}"365 if [[ "$cur" == *"$trigger" ]] && [[ $cur != *'$('* ]] && [[ $cur != *':='* ]] && [[ $cur != *'`'* ]]; then366 cur=${cur:0:${#cur}-${#trigger}}367368 selected=$(FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse --bind=ctrl-z:ignore ${FZF_DEFAULT_OPTS-} ${FZF_COMPLETION_OPTS-} $str_arg" __fzf_comprun "${rest[0]}" "${args[@]}" -q "$cur" | $post | tr '\n' ' ')368 selected=$(FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse --bind=ctrl-z:ignore ${FZF_DEFAULT_OPTS-} ${FZF_COMPLETION_OPTS-} $str_arg" __fzf_comprun "${rest[0]}" "${args[@]}" -q "$cur" | $post | command tr '\n' ' ')369 selected=${selected% } # Strip trailing space not to repeat "-o nospace"370 if [[ -n "$selected" ]]; then371 COMPREPLY=("$selected")372 else
30 unmodified lines
403 )404}405406_fzf_proc_completion_post() {407 awk '{print $2}'407 command awk '{print $2}'408}409410__fzf_list_hosts() {411 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 '[*?%]') \412 <(command grep -oE '^[[a-z0-9.,:-]+' ~/.ssh/known_hosts | tr ',' '\n' | tr -d '[' | awk '{ print $1 " " $1 }') \411 command cat <(command tail -n +1 ~/.ssh/config ~/.ssh/config.d/* /etc/ssh/ssh_config 2> /dev/null | command grep -i '^\s*host\(name\)\? ' | command awk '{for (i = 2; i <= NF; i++) print $1 " " $i}' | command grep -v '[*?%]') \412 <(command grep -oE '^[[a-z0-9.,:-]+' ~/.ssh/known_hosts | command tr ',' '\n' | command tr -d '[' | command awk '{ print $1 " " $1 }') \413 <(command grep -v '^\s*\(#\|$\)' /etc/hosts | command grep -Fv '0.0.0.0') |414 awk -v "user=$1" '{if (length($2) > 0) {print user $2}}' | sort -u414 command awk -v "user=$1" '{if (length($2) > 0) {print user $2}}' | command sort -u415}416417_fzf_host_completion() {418 _fzf_complete +m -- "$@" < <(__fzf_list_hosts "")
18 unmodified lines
437}438439_fzf_var_completion() {440 _fzf_complete -m -- "$@" < <(441 declare -xp | sed -En 's|^declare [^ ]+ ([^=]+).*|\1|p'441 declare -xp | command sed -En 's|^declare [^ ]+ ([^=]+).*|\1|p'442 )443}444445_fzf_alias_completion() {446 _fzf_complete -m -- "$@" < <(447 alias | sed -En 's|^alias ([^=]+).*|\1|p'447 alias | command sed -En 's|^alias ([^=]+).*|\1|p'448 )449}450451# fzf options
79 unmodified lines
modified:shell/key-bindings.bash+2 added-2 removed