[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
Provenance
- Commit
561e0b0- Tree
5e4792e- Author
Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>- Committer
GitHub <noreply@github.com>- Parent
404b6a8
2 files changed+14 added−14 removed
modified:shell/completion.bash+12 added-12 removed
16 unmodified lines17 _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 }23 fi24 25 if ! 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 }31 fi32 33 ###########################################################287 unmodified lines321 fi322 printf '\e[5n'323 return 0324 fi325- dir=$(dirname "$dir")325+ dir=$(command dirname "$dir")326 [[ "$dir" =~ /$ ]] || dir="$dir"/327 done328 else329 shift25 unmodified lines355 rest=("$@")356 fi357 358 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'361 362 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}}367 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 | 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 else30 unmodified lines403 )404 }405 406 _fzf_proc_completion_post() {407- awk '{print $2}'407+ command awk '{print $2}'408 }409 410 __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 }416 417 _fzf_host_completion() {418 _fzf_complete +m -- "$@" < <(__fzf_list_hosts "")18 unmodified lines437 }438 439 _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 }444 445 _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 }450 451 # fzf options79 unmodified linesmodified:shell/key-bindings.bash+2 added-2 removed
19 unmodified lines2021222324242526272814 unmodified lines4344454647474849505182 unmodified lines19 unmodified lines local cmd opts cmd="${FZF_CTRL_T_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \ -o -type f -print \ -o -type d -print \ -o -type l -print 2> /dev/null | cut -b3-"}" -o -type l -print 2> /dev/null | command cut -b3-"}" opts="--height ${FZF_TMUX_HEIGHT:-40%} --bind=ctrl-z:ignore --reverse --scheme=path ${FZF_DEFAULT_OPTS-} ${FZF_CTRL_T_OPTS-} -m" eval "$cmd" | FZF_DEFAULT_OPTS="$opts" $(__fzfcmd) "$@" | while read -r item; do14 unmodified lines
__fzf_cd__() { local cmd opts dir cmd="${FZF_ALT_C_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \ -o -type d -print 2> /dev/null | cut -b3-"}" -o -type d -print 2> /dev/null | command cut -b3-"}" opts="--height ${FZF_TMUX_HEIGHT:-40%} --bind=ctrl-z:ignore --reverse --scheme=path ${FZF_DEFAULT_OPTS-} ${FZF_ALT_C_OPTS-} +m" dir=$(set +o pipefail; eval "$cmd" | FZF_DEFAULT_OPTS="$opts" $(__fzfcmd)) && printf 'builtin cd -- %q' "$dir"}
82 unmodified lines