#!/bin/bash _lxcd_completion() { local cur prev words cword _init_completion || return local commands="create clone rename enter list delete add stop start restart" if [ $cword -eq 1 ]; then COMPREPLY=($(compgen -W "-v --verbose ${commands}" -- "$cur")) return 0 fi local subcommand="${words[1]}" # Use sudo for lxc if the user isn't in the lxd group if id -nG | grep -qw lxd 2>/dev/null; then local LXC="lxc" else local LXC="sudo lxc" fi # Fetch lxcd-managed container names local containers=$($LXC list user.lxcd=true -c n --format csv 2>/dev/null | tr '\n' ' ') case "${subcommand}" in create) if [[ "$cur" == -* ]]; then COMPREPLY=($(compgen -W "--nested --aptcache -i --image -m --minimal -w --workspace" -- "$cur")) else COMPREPLY=($(compgen -W "ubuntu: ubuntu/24.04 ubuntu/22.04 debian/12 debian/11" -- "$cur")) fi ;; clone) if [ $cword -eq 2 ]; then COMPREPLY=($(compgen -W "${containers}" -- "$cur")) fi ;; rename|mv) if [ $cword -eq 2 ]; then COMPREPLY=($(compgen -W "${containers}" -- "$cur")) fi ;; enter|delete|stop|start|restart) COMPREPLY=($(compgen -W "${containers}" -- "$cur")) ;; add) if [ $cword -eq 2 ]; then COMPREPLY=($(compgen -W "${containers}" -- "$cur")) elif [[ "$cur" == -* ]]; then COMPREPLY=($(compgen -W "--nested --aptcache --map --unmap" -- "$cur")) fi ;; *) COMPREPLY=() ;; esac } complete -F _lxcd_completion lxcd