chubin / cheat.sh

the only cheat sheet you need
https://cheat.sh/
MIT License
38.15k stars 1.78k forks source link

Autocompletion on Bash on Mac not working #304

Open mnott opened 3 years ago

mnott commented 3 years ago

Each time I'm doing a TAB, I see things like this:

-bash: _get_comp_words_by_ref: command not found

I can avoid it by catching the errors:

$ cat ~/.bash.d/cht.sh 
_cht_complete()
{
    local cur prev opts
    _get_comp_words_by_ref -n : cur 2>/dev/null

    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    opts="$(curl -s cheat.sh/:list)"

    if [ ${COMP_CWORD} = 1 ]; then
      COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
      __ltrim_colon_completions "$cur" 2>/dev/null
    fi
    return 0
}
complete -F _cht_complete cht.sh

Notice the 2>/dev/null for both commands.

shazaum commented 2 years ago

Do you have bash-completion installed? If not, you can try brew install bash_completion