cheat.sh icon indicating copy to clipboard operation
cheat.sh copied to clipboard

Autocompletion on Bash on Mac not working

Open mnott opened this issue 3 years ago • 1 comments

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.

mnott avatar Sep 04 '21 05:09 mnott

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

shazaum avatar Oct 13 '21 03:10 shazaum