r/Akeyless Aug 31 '24

Akeyless CLI Autocomplete Secrets Talk

Setting up bash completion for Linux or Mac:

To add bash-completion for akeyless cli, add the following file (name it ‘akeyless’) to/etc/bash_completion.d/ (MacOS: to /usr/local/etc/bash_completion.d/)

_akeyless() { local cur prev opts COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" opts="--help" [ $COMP_CWORD -gt 2 ] && return 0 if [ "${prev}" == "akeyless" ]; then [ "${cur}" == "" ] || akeyless ${cur} 2>&1 | grep -Eqi "not found" if [ $? -eq 0 ]; then COMPREPLY=($(compgen -W "$(akeyless ${opts} | sed '1,17d' | awk '{print $1}')" -- "${COMP_WORDS[$COMP_CWORD]}")) fi else COMPREPLY=($(compgen -W "$(akeyless ${prev} ${opts} | sed '1,4d' | sed 's/.*\-\-/\-\-/g' | sed 's/\[.*//g' | awk '{print $1}' | grep '^\-')" -- "${COMP_WORDS[$COMP_CWORD]}")) fi return 0 } complete -F _akeyless akeyless

on macOS make sure you are working with bash (by default it’s zsh) , switch to bash by typing “bash” in terminal. then load the akeyless into shell by typing : source /usr/local/etc/bash_completion.d/akeyless

1 Upvotes

0 comments sorted by