1#!/usr/bin/env bash
2
3_nixos-container() {
4 local cur prev opts
5 COMPREPLY=()
6 cur="${COMP_WORDS[COMP_CWORD]}"
7 prev="${COMP_WORDS[COMP_CWORD-1]}"
8 opts="list create destroy start stop status update login root-login run show-ip show-host-key"
9 startstop_opts=$(nixos-container list)
10 update_opts="--config"
11
12 if [[ "$prev" == "nixos-container" ]]
13 then
14 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
15 return 0
16 fi
17
18 if [[ $(echo "$opts" | grep "$prev") ]]
19 then
20 if [[ "$prev" == "start" || "$prev" == "stop" ]]
21 then
22 COMPREPLY=( $(compgen -W "${startstop_opts}" -- ${cur}) )
23 return 0
24 elif [[ "$prev" == "update" ]]
25 then
26 COMPREPLY=( $(compgen -W "${update_opts}" -- ${cur}) )
27 return 0
28 fi
29 fi
30}
31
32complete -F _nixos-container nixos-container
33