function _incus_container { incus list --format csv --columns n } function _active_users { echo root miaou-exec "$container" -- awk -F: '$3 >= 1000 && $7 !~ /nologin|false/ {print $1}' /etc/passwd } function _miaou_login { local cur="${COMP_WORDS[COMP_CWORD]}" local prev="${COMP_WORDS[COMP_CWORD - 1]}" local container="${COMP_WORDS[1]}" case $COMP_CWORD in 1) # first argument — containers COMPREPLY=($(compgen -W "$(_incus_container)" -- "$cur")) ;; 2) # second argument - options COMPREPLY=($(compgen -W "--user -u" -- "$cur")) ;; 3) if [[ $prev =~ ^(--user|-u) ]]; then # user expected COMPREPLY=($(compgen -W "$(_active_users "$container")" -- "$cur")) fi ;; esac } complete -F _miaou_login "miaou-login"