cheat.sh
cheat.sh copied to clipboard
Autocompletion on Bash on Mac not working
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.
Do you have bash-completion installed? If not, you can try brew install bash_completion