Shell completion for bacon gives `command not found`

Description:

In a shell supporting bacon completion, bacon <TAB> gives "command not found".

Additional info:

  • package version(s): 3.12.0
  • config and/or log files: N/A
  • link to upstream bug report, if any: N/A

Steps to reproduce:

  1. Open Bash as an example
  2. Type bacon
  3. Press <TAB>
  4. Bash outputs: bash: /build/bacon/src/bacon/target/release/bacon: No such file or directory

Possibly caused by:

131532a0

local _binary="target/release/$pkgname"

# ...

# completions
install -vDm644 <(COMPLETE=bash   "$_binary") "$pkgdir/usr/share/bash-completion/completions/$pkgname"
install -vDm644 <(COMPLETE=zsh    "$_binary") "$pkgdir/usr/share/zsh/site-functions/_$pkgname"
install -vDm644 <(COMPLETE=fish   "$_binary") "$pkgdir/usr/share/fish/vendor_completions.d/$pkgname.fish"
install -vDm644 <(COMPLETE=elvish "$_binary") "$pkgdir/usr/share/elvish/lib/$pkgname.elv"

$_binary here (/build/bacon/src/bacon/target/release/bacon) is copy-pasted into bacon's completion script, proof:

$ COMPLETE=bash /usr/bin/bacon 

_clap_complete_bacon() {
    local IFS=$'\013'
    local _CLAP_COMPLETE_INDEX=${COMP_CWORD}
    local _CLAP_COMPLETE_COMP_TYPE=${COMP_TYPE}
    if compopt +o nospace 2> /dev/null; then
        local _CLAP_COMPLETE_SPACE=false
    else
        local _CLAP_COMPLETE_SPACE=true
    fi
    COMPREPLY=( $( \
        _CLAP_IFS="$IFS" \
        _CLAP_COMPLETE_INDEX="$_CLAP_COMPLETE_INDEX" \
        _CLAP_COMPLETE_COMP_TYPE="$_CLAP_COMPLETE_COMP_TYPE" \
        COMPLETE="bash" \
        "/usr/bin/bacon" -- "${COMP_WORDS[@]}" \    # <-- This line
    ) )
    if [[ $? != 0 ]]; then
        unset COMPREPLY
    elif [[ $SUPPRESS_SPACE == 1 ]] && [[ "${COMPREPLY-}" =~ [=/:]$ ]]; then
        compopt -o nospace
    fi
}
if [[ "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 || "${BASH_VERSINFO[0]}" -gt 4 ]]; then
    complete -o nospace -o bashdefault -o nosort -F _clap_complete_bacon bacon
else
    complete -o nospace -o bashdefault -F _clap_complete_bacon bacon
fi

This can be solved by replace arg0 with exec -a when generating completions:

install -vDm644 <(COMPLETE=bash exec -a bacon "$_binary") "$pkgdir/usr/share/bash-completion/completions/$pkgname"
# Same for other shells
Edited by Jisu Woniu