acmesh-official / acme.sh

A pure Unix shell script implementing ACME client protocol
https://acme.sh
GNU General Public License v3.0
38.66k stars 4.91k forks source link

Shell completion, Completion definitions for Bash, Fish and Zsh #307

Open Neilpang opened 7 years ago

Neilpang commented 7 years ago

Shell completion, Completion definitions for Bash, Fish and Zsh

Roy-Orbison commented 1 year ago

Would this help?

_comp_cmd_acme_sh()
{
    local cur prev words cword
    _init_completion -n : || return

    local commands
    commands='--help --version --install --uninstall --upgrade --issue --deploy --install-cert
        --renew --renew-all --revoke --remove --list --info --to-pkcs12 --to-pkcs8 --sign-csr
        --show-csr --create-csr --create-domain-key --update-account --register-account
        --deactivate-account --create-account-key --install-cronjob --uninstall-cronjob --cron
        --set-notify --deactivate --set-default-ca --set-default-chain'

    if (( cword == 1 )); then
        COMPREPLY=( $(compgen -W "$commands" -- "$cur") )
        return 0
    fi

    local command="${words[1]}"

    case "$prev" in
        --domain | \
        --challenge-alias | \
        --domain-alias)
            COMPREPLY=( $( compgen -W "$(acme.sh --list | tail -n +2 | grep -Eo '^[^[:space:]]+')" -- "$cur" ) )
            return 0
            ;;
        --preferred-chain | \
        --valid-to | \
        --valid-from | \
        --dnssleep | \
        --eab-kid | \
        --eab-hmac-key | \
        --reloadcmd | \
        --server | \
        --useragent | \
        --email | \
        -m | \
        --days | \
        --httpport | \
        --tlsport | \
        --local-address | \
        --pre-hook | \
        --post-hook | \
        --renew-hook | \
        --deploy-hook | \
        --branch | \
        -b | \
        --notify-hook | \
        --notify-source | \
        --password)
            # These all need a value. Some could have smarter completion but
            # better to offer nothing over more options.
            COMPREPLY=()
            return 0
            ;;
        --debug)
            if [[ "$cur" != -* ]]; then
                COMPREPLY=( $( compgen -W '0 1 2 3' -- "$cur" ) )
                return 0
            fi
            ;;
        --webroot | \
        --home | \
        --cert-home | \
        --config-home | \
        --ca-path)
            _filedir -d
            return 0
            ;;
        --dns)
            if [[ "$cur" != -* ]]; then
                COMPREPLY=()
                return 0
            fi
            ;;
        --keylength | \
        -k)
            COMPREPLY=( $( compgen -W '2048 3072 4096 8192 ec-256 ec-384 ec-521' -- "$cur" ) )
            return 0
            ;;
        --accountkeylength | \
        -ak)
            COMPREPLY=( $( compgen -W '2048 3072 4096' -- "$cur" ) )
            return 0
            ;;
        --log)
            if [[ "$cur" != -* ]]; then
                _filedir
                return 0
            fi
            ;;
        --log-level)
            COMPREPLY=( $( compgen -W '1 2' -- "$cur" ) )
            return 0
            ;;
        --syslog)
            COMPREPLY=( $( compgen -W '0 3 6 7' -- "$cur" ) )
            return 0
            ;;
        --cert-file | \
        --key-file | \
        --ca-file | \
        --fullchain-file | \
        --accountconf | \
        --accountkey | \
        --ca-bundle | \
        --csr | \
        --openssl-bin)
            _filedir
            return 0
            ;;
        --auto-upgrade)
            if [[ "$cur" != -* ]]; then
                COMPREPLY=( $( compgen -W '0 1' -- "$cur" ) )
                return 0
            fi
            ;;
        --notify-level)
            COMPREPLY=( $( compgen -W '0 1 2 3' -- "$cur" ) )
            return 0
            ;;
        --notify-mode)
            COMPREPLY=( $( compgen -W '0 1' -- "$cur" ) )
            return 0
            ;;
        --revoke-reason)
            COMPREPLY=({0..10})
            COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -- "$cur" ) )
            return 0
            ;;
    esac

    local opts
    opts='--domain --challenge-alias --domain-alias --preferred-chain --valid-to --valid-from
        --force --staging --test --debug --output-insecure --webroot --standalone --alpn
        --stateless --apache --dns --dnssleep --keylength --accountkeylength --log --log-level
        --syslog --eab-kid --eab-hmac-key --cert-file --key-file --ca-file --fullchain-file
        --reloadcmd --server --accountconf --home --config-home --useragent --httpport --tlsport
        --local-address --insecure --ca-bundle --ca-path --no-color --force-color --csr
        --pre-hook --post-hook --renew-hook --deploy-hook --ocsp-must-staple
        --always-force-new-domain-key --listen-v4 --listen-v6 --openssl-bin --use-wget
        --yes-I-know-dns-manual-mode-enough-go-ahead-please --notify-level --notify-mode
        --notify-hook --notify-source'
    case "$command" in
        --install)
            opts+=' --cert-home --email --accountkey --no-cron --no-profile'
            ;;
        --update-account)
            opts+=' --email'
            ;;
        --issue)
            opts+=' --days'
            ;;
        --list)
            opts+=' --listraw'
            ;;
        --renew-all)
            opts+=' --stop-renew-on-error'
            ;;
        --upgrade)
            opts+=' --auto-upgrade --branch'
            ;;
        --revoke)
            opts+=' --revoke-reason'
            ;;
        --to-pkcs12)
            opts+=' --password'
            ;;
    esac
    case "$command" in
        --install-cert | \
        -i | \
        --renew | \
        -r | \
        --revoke | \
        --to-pkcs12 | \
        --create-csr | \
        -ccr)
            opts+=' --ecc'
            ;;
    esac
    COMPREPLY=( $( compgen -W "$opts" -- "$cur" ) )
} &&
complete -F _comp_cmd_acme_sh acme.sh