3 # We're faking a `nix build` command-line to re-use Nix's own completion
4 # for the few options passed through to Nix.
5 _nixos-rebuild_pretend-nix
() {
6 COMP_LINE
="nix build ${COMP_LINE}"
7 # number of prepended chars
8 (( COMP_POINT
= COMP_POINT
+ 10))
14 # Add the amount of prepended words
15 (( COMP_CWORD
= COMP_CWORD
+ 2))
22 local subcommandGiven
=0
28 # Arrays are re-ordered by the completion, so it's fine to sort them in logical chunks
32 # nixos-rebuild options
35 --profile-name -p # name
37 --specialisation -c # name
42 # Used with list-generations
45 # generation switching options
55 --override-input # input-name flake-uri
64 --use-substitutes --substitute-on-destination -s
69 --builders # builder-spec
73 --max-jobs -j # number
78 local all_subcommands
=(
82 build-vm-with-bootloader
91 # Suggest arguments that can be consumed under some conditions only
92 for word
in "${COMP_WORDS[@]}"; do
93 for subcommand
in "${all_subcommands[@]}"; do
94 if [[ "$word" == "$subcommand" ]]; then
100 # Fake out a way to complete the second arg to some options
101 case "${COMP_WORDS[COMP_CWORD-2]}" in
103 prev
="--override-input_2"
116 if [[ "$curr" == "" ]]; then
117 COMPREPLY
=( /nix
/var
/nix
/profiles
/* )
119 COMPREPLY
=( "$curr"* )
123 --build-host|
--target-host|
-t|
-h)
124 _known_hosts_real
"$curr"
132 _nixos-rebuild_pretend-nix
135 _nixos-rebuild_pretend-nix
138 _nixos-rebuild_pretend-nix
141 _nixos-rebuild_pretend-nix
144 _nixos-rebuild_pretend-nix
147 _nixos-rebuild_pretend-nix
150 _nixos-rebuild_pretend-nix
153 _nixos-rebuild_pretend-nix
157 if [[ "$curr" == -* ]] ||
(( subcommandGiven
)); then
158 COMPREPLY
=( $
(compgen
-W "${all_args[*]}" -- "$2") )
160 COMPREPLY
=( $
(compgen
-W "${all_subcommands[*]}" -- "$2") )
166 complete
-F _nixos-rebuild nixos-rebuild