Last active
August 1, 2025 06:03
-
-
Save Roy-Orbison/9768b938bc5dfbac69b7e20d3387a416 to your computer and use it in GitHub Desktop.
Bash completion for acme.sh. Save in /usr/share/bash-completion/completions or similar.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_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 | \ | |
-d | \ | |
--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 | \ | |
--extended-key-usage | \ | |
--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 | \ | |
-w | \ | |
--home | \ | |
--cert-home | \ | |
--config-home | \ | |
--ca-path) | |
_filedir -d | |
return 0 | |
;; | |
--dns) | |
if [[ "$cur" != -* ]]; then | |
COMPREPLY=() | |
local dnsapis | |
if dnsapis="$( compgen -G "$HOME/.acme.sh/dnsapi/dns_?*.sh" )"; then | |
readarray -t COMPREPLY <<<"$dnsapis" | |
COMPREPLY=( "${COMPREPLY[@]##*/}" ) | |
COMPREPLY=( "${COMPREPLY[@]%.sh}" ) | |
COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -- "$cur" ) ) | |
fi | |
unset dnsapis | |
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-profile --no-color --force-color | |
--csr --pre-hook --post-hook --renew-hook --deploy-hook --extended-key-usage | |
--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 | \ | |
--remove | \ | |
--revoke | \ | |
--deploy | \ | |
--to-pkcs12 | \ | |
--create-csr | \ | |
-ccr) | |
opts+=' --ecc' | |
;; | |
esac | |
COMPREPLY=( $( compgen -W "$opts" -- "$cur" ) ) | |
} && | |
complete -F _comp_cmd_acme_sh acme.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment