home-assistant-ecosystem / home-assistant-cli

:computer: Command-line tool for Home Assistant
Other
446 stars 69 forks source link

Change autocomplete keybind #410

Open robertoash opened 11 months ago

robertoash commented 11 months ago

I am wondering if it is possible to change the autocomplete keybind. I use zsh-autocomplete which also uses TAB for autocomplete so I am guessing the two are conflicting. If I could change the keybind via a config file to , for example, that would be a great solution.

I don't know enough about Python but I am learning. I tried to look at the code but couldn't find where TAB is defined as the autocomplete keybind. If you could point me in the right direction maybe I can try to figure out how to change it?

varenc commented 6 months ago

You're talking about autocompletion for your shell? That's all handled by your shell and not something that's in the Python code or even in the shell code that defines the hass-cli autocompletion function. Are you sure that auto-completion for hass-cli is working for you? It should work peacefully with all your other shell completions.

On my zsh shell I see that the hass-cli completion is defined in the function _hass_cli_completion. I found this with echo $_comps[hass-cli]. If you don't see a completion there than you don't have it set up. I use zsh-autocomplete too and it works peacefully with the hass-cli completion.

Also here's the source of my _hass_cli_completion for reference:

#compdef hass-cli

_hass_cli_completion() {
    local -a completions
    local -a completions_with_descriptions
    local -a response
    (( ! $+commands[hass-cli] )) && return 1

    response=("${(@f)$(env COMP_WORDS="${words[*]}" COMP_CWORD=$((CURRENT-1)) _HASS_CLI_COMPLETE=zsh_complete hass-cli)}")

    for type key descr in ${response}; do
        if [[ "$type" == "plain" ]]; then
            if [[ "$descr" == "_" ]]; then
                completions+=("$key")
            else
                completions_with_descriptions+=("$key":"$descr")
            fi
        elif [[ "$type" == "dir" ]]; then
            _path_files -/
        elif [[ "$type" == "file" ]]; then
            _path_files -f
        fi
    done

    if [ -n "$completions_with_descriptions" ]; then
        _describe -V unsorted completions_with_descriptions -U
    fi

    if [ -n "$completions" ]; then
        compadd -U -V unsorted -a completions
    fi
}

compdef _hass_cli_completion hass-cli;