MisterTea / EternalTerminal

Re-Connectable secure remote shell
https://mistertea.github.io/EternalTerminal/
Apache License 2.0
2.98k stars 168 forks source link

bash/zsh completion? #309

Open AndrewSB opened 4 years ago

AndrewSB commented 4 years ago

Hey! I couldn't find documentation or any issues about this:

Does et support shell completion? specifically interested in tab completion for hosts in my ssh config

Thank you for continuing to maintain this great package

MisterTea commented 4 years ago

Not yet but it's a good idea

tgarm commented 4 years ago

I've just wrote a bash-completion script by modify the mosh one, and tested very simply. Would you try it and if it works, merge it into the main tree.

# Bash completions for Eternal Terminal (ET).         -*- shell-script -*-

__et_init_completion()
{
    if declare -F _init_completions >/dev/null 2>&1; then
        _init_completion
    else
        COMPREPLY=()
        _get_comp_words_by_ref cur prev words cword
    fi
}

_et () {
    local cur

    __et_init_completion || return

    local simple_flags="-N -h -u -p -r -x -v -f"
    local flags="--version --username --host --port --command --prefix
    --reversetunnel --jumphost --jport --kill-other-sessions --verbose
    --logtostdout --silent --no-terminal --forward-ssh-agent --ssh-socket
    --serverfifo"

    if [[ "$cur" == --* && "$COMP_CWORD" == 1 ]]; then
        COMPREPLY=($(compgen -W "$flags" -- "$cur"))
    elif [[ "$cur" == -* && "$COMP_CWORD" == 1 ]]; then
        COMPREPLY=($(compgen -W "$simple_flags" -- "$cur"))
    else
        _known_hosts_real -a "$cur"
    fi
}

complete -o nospace -F _et et

How to try: Just copy it to _/usr/local/etc/bashcompletion.d/et

Cuz I'm not familiar with the installation script, so I did not make a PR. Forgive me.

xgdgsc commented 3 years ago

Does the above script read from ~/.ssh/config ? How to add from https://github.com/Bash-it/bash-it/blob/master/completion/available/ssh.completion.bash ?