installShellFiles: Add nushell support to installShellCompletion (#428168)

authored by

John Ericson and committed by
GitHub
954b76a9 5360dcde

+46 -15
+5 -3
doc/hooks/installShellFiles.section.md
··· 58 completion files. 59 60 By default it will autodetect the shell type from the completion file extension, 61 - but you may also specify it by passing one of `--bash`, `--fish`, or 62 - `--zsh`. These flags apply to all paths listed after them (up until another 63 shell flag is given). Each path may also have a custom installation name 64 provided by providing a flag `--name NAME` before the path. If this flag is not 65 provided, zsh completions will be renamed automatically such that `foobar.zsh` ··· 77 # explicit behavior 78 installShellCompletion --bash --name foobar.bash share/completions.bash 79 installShellCompletion --fish --name foobar.fish share/completions.fish 80 installShellCompletion --zsh --name _foobar share/completions.zsh 81 # implicit behavior 82 - installShellCompletion share/completions/foobar.{bash,fish,zsh} 83 ''; 84 } 85 ``` ··· 104 installShellCompletion --cmd foobar \ 105 --bash <($out/bin/foobar --bash-completion) \ 106 --fish <($out/bin/foobar --fish-completion) \ 107 --zsh <($out/bin/foobar --zsh-completion) 108 ''; 109 }
··· 58 completion files. 59 60 By default it will autodetect the shell type from the completion file extension, 61 + but you may also specify it by passing one of `--bash`, `--fish`, `--zsh`, or 62 + `--nushell`. These flags apply to all paths listed after them (up until another 63 shell flag is given). Each path may also have a custom installation name 64 provided by providing a flag `--name NAME` before the path. If this flag is not 65 provided, zsh completions will be renamed automatically such that `foobar.zsh` ··· 77 # explicit behavior 78 installShellCompletion --bash --name foobar.bash share/completions.bash 79 installShellCompletion --fish --name foobar.fish share/completions.fish 80 + installShellCompletion --nushell --name foobar share/completions.nu 81 installShellCompletion --zsh --name _foobar share/completions.zsh 82 # implicit behavior 83 + installShellCompletion share/completions/foobar.{bash,fish,zsh,nu} 84 ''; 85 } 86 ``` ··· 105 installShellCompletion --cmd foobar \ 106 --bash <($out/bin/foobar --bash-completion) \ 107 --fish <($out/bin/foobar --fish-completion) \ 108 + --nushell <($out/bin/foobar --nushell-completion) \ 109 --zsh <($out/bin/foobar --zsh-completion) 110 ''; 111 }
+2
doc/release-notes/rl-2511.section.md
··· 88 89 - [`homebox` 0.20.0](https://github.com/sysadminsmedia/homebox/releases/tag/v0.20.0) changed how assets are stored and hashed. It is recommended to back up your database before this update. 90 91 - New hardening flags, `strictflexarrays1` and `strictflexarrays3` were made available, corresponding to the gcc/clang options `-fstrict-flex-arrays=1` and `-fstrict-flex-arrays=3` respectively. 92 93 - `gramps` has been updated to 6.0.0
··· 88 89 - [`homebox` 0.20.0](https://github.com/sysadminsmedia/homebox/releases/tag/v0.20.0) changed how assets are stored and hashed. It is recommended to back up your database before this update. 90 91 + - `installShellCompletion`: now supports Nushell completion files 92 + 93 - New hardening flags, `strictflexarrays1` and `strictflexarrays3` were made available, corresponding to the gcc/clang options `-fstrict-flex-arrays=1` and `-fstrict-flex-arrays=3` respectively. 94 95 - `gramps` has been updated to 6.0.0
+12 -7
pkgs/by-name/in/installShellFiles/setup-hook.sh
··· 51 # installShellCompletion [--cmd <name>] ([--bash|--fish|--zsh] [--name <name>] <path>)... 52 # 53 # Each path is installed into the appropriate directory for shell completions for the given shell. 54 - # If one of `--bash`, `--fish`, or `--zsh` is given the path is assumed to belong to that shell. 55 - # Otherwise the file extension will be examined to pick a shell. If the shell is unknown a warning 56 - # will be logged and the command will return a non-zero status code after processing any remaining 57 - # paths. Any of the shell flags will affect all subsequent paths (unless another shell flag is 58 - # given). 59 # 60 # If the shell completion needs to be renamed before installing the optional `--name <name>` flag 61 # may be given. Any name provided with this flag only applies to the next path. ··· 84 # 85 # installShellCompletion --bash --name foobar.bash share/completions.bash 86 # installShellCompletion --fish --name foobar.fish share/completions.fish 87 # installShellCompletion --zsh --name _foobar share/completions.zsh 88 # 89 # Or to use shell newline escaping to split a single invocation across multiple lines: ··· 91 # installShellCompletion --cmd foobar \ 92 # --bash <($out/bin/foobar --bash-completion) \ 93 # --fish <($out/bin/foobar --fish-completion) \ 94 # --zsh <($out/bin/foobar --zsh-completion) 95 # 96 # If any argument is `--` the remaining arguments will be treated as paths. ··· 100 # Parse arguments 101 if (( parseArgs )); then 102 case "$arg" in 103 - --bash|--fish|--zsh) 104 shell=${arg#--} 105 continue;; 106 --name) ··· 146 elif [[ -p "$arg" ]]; then 147 # this is a named fd or fifo 148 if [[ -z "$curShell" ]]; then 149 - nixErrorLog "${FUNCNAME[0]}: named pipe requires one of --bash, --fish, or --zsh" 150 return 1 151 elif [[ -z "$name" && -z "$cmdname" ]]; then 152 nixErrorLog "${FUNCNAME[0]}: named pipe requires one of --cmd or --name" ··· 161 case "$argbase" in 162 ?*.bash) curShell=bash;; 163 ?*.fish) curShell=fish;; 164 ?*.zsh) curShell=zsh;; 165 *) 166 if [[ "$argbase" = _* && "$argbase" != *.* ]]; then ··· 182 elif [[ -n "$cmdname" ]]; then 183 case "$curShell" in 184 bash|fish) outName=$cmdname.$curShell;; 185 zsh) outName=_$cmdname;; 186 *) 187 # Our list of shells is out of sync with the flags we accept or extensions we detect. ··· 193 case "$curShell" in 194 bash) sharePath=bash-completion/completions;; 195 fish) sharePath=fish/vendor_completions.d;; 196 zsh) 197 sharePath=zsh/site-functions 198 # only apply automatic renaming if we didn't have a manual rename
··· 51 # installShellCompletion [--cmd <name>] ([--bash|--fish|--zsh] [--name <name>] <path>)... 52 # 53 # Each path is installed into the appropriate directory for shell completions for the given shell. 54 + # If one of `--bash`, `--fish`, `--zsh`, or `--nushell` is given the path is assumed to belong to 55 + # that shell. Otherwise the file extension will be examined to pick a shell. If the shell is 56 + # unknown a warning will be logged and the command will return a non-zero status code after 57 + # processing any remaining paths. Any of the shell flags will affect all subsequent paths (unless 58 + # another shell flag is given). 59 # 60 # If the shell completion needs to be renamed before installing the optional `--name <name>` flag 61 # may be given. Any name provided with this flag only applies to the next path. ··· 84 # 85 # installShellCompletion --bash --name foobar.bash share/completions.bash 86 # installShellCompletion --fish --name foobar.fish share/completions.fish 87 + # installShellCompletion --nushell --name foobar share/completions.nu 88 # installShellCompletion --zsh --name _foobar share/completions.zsh 89 # 90 # Or to use shell newline escaping to split a single invocation across multiple lines: ··· 92 # installShellCompletion --cmd foobar \ 93 # --bash <($out/bin/foobar --bash-completion) \ 94 # --fish <($out/bin/foobar --fish-completion) \ 95 + # --nushell <($out/bin/foobar --nushell-completion) 96 # --zsh <($out/bin/foobar --zsh-completion) 97 # 98 # If any argument is `--` the remaining arguments will be treated as paths. ··· 102 # Parse arguments 103 if (( parseArgs )); then 104 case "$arg" in 105 + --bash|--fish|--zsh|--nushell) 106 shell=${arg#--} 107 continue;; 108 --name) ··· 148 elif [[ -p "$arg" ]]; then 149 # this is a named fd or fifo 150 if [[ -z "$curShell" ]]; then 151 + nixErrorLog "${FUNCNAME[0]}: named pipe requires one of --bash, --fish, --zsh, or --nushell" 152 return 1 153 elif [[ -z "$name" && -z "$cmdname" ]]; then 154 nixErrorLog "${FUNCNAME[0]}: named pipe requires one of --cmd or --name" ··· 163 case "$argbase" in 164 ?*.bash) curShell=bash;; 165 ?*.fish) curShell=fish;; 166 + ?*.nu) curShell=nushell;; 167 ?*.zsh) curShell=zsh;; 168 *) 169 if [[ "$argbase" = _* && "$argbase" != *.* ]]; then ··· 185 elif [[ -n "$cmdname" ]]; then 186 case "$curShell" in 187 bash|fish) outName=$cmdname.$curShell;; 188 + nushell) outName=$cmdname.nu;; 189 zsh) outName=_$cmdname;; 190 *) 191 # Our list of shells is out of sync with the flags we accept or extensions we detect. ··· 197 case "$curShell" in 198 bash) sharePath=bash-completion/completions;; 199 fish) sharePath=fish/vendor_completions.d;; 200 + nushell) sharePath=nushell/vendor/autoload;; 201 zsh) 202 sharePath=zsh/site-functions 203 # only apply automatic renaming if we didn't have a manual rename
+7 -1
pkgs/by-name/in/installShellFiles/tests/install-completion-cmd.nix
··· 14 echo bar > bar.zsh 15 echo baz > baz.fish 16 echo qux > qux.fish 17 18 - installShellCompletion --cmd foobar --bash foo.bash --zsh bar.zsh --fish baz.fish --name qux qux.fish 19 20 cmp foo.bash $out/share/bash-completion/completions/foobar.bash 21 cmp bar.zsh $out/share/zsh/site-functions/_foobar 22 cmp baz.fish $out/share/fish/vendor_completions.d/foobar.fish 23 cmp qux.fish $out/share/fish/vendor_completions.d/qux 24 ''
··· 14 echo bar > bar.zsh 15 echo baz > baz.fish 16 echo qux > qux.fish 17 + echo buzz > buzz.nu 18 19 + installShellCompletion \ 20 + --cmd foobar --bash foo.bash \ 21 + --zsh bar.zsh \ 22 + --fish baz.fish --name qux qux.fish \ 23 + --nushell --cmd buzzbar buzz.nu 24 25 cmp foo.bash $out/share/bash-completion/completions/foobar.bash 26 cmp bar.zsh $out/share/zsh/site-functions/_foobar 27 cmp baz.fish $out/share/fish/vendor_completions.d/foobar.fish 28 cmp qux.fish $out/share/fish/vendor_completions.d/qux 29 + cmp buzz.nu $out/share/nushell/vendor/autoload/buzzbar.nu 30 ''
+3 -1
pkgs/by-name/in/installShellFiles/tests/install-completion-fifo.nix
··· 13 installShellCompletion \ 14 --bash --name foo.bash <(echo foo) \ 15 --zsh --name _foo <(echo bar) \ 16 - --fish --name foo.fish <(echo baz) 17 18 [[ $(<$out/share/bash-completion/completions/foo.bash) == foo ]] || { echo "foo.bash comparison failed"; exit 1; } 19 [[ $(<$out/share/zsh/site-functions/_foo) == bar ]] || { echo "_foo comparison failed"; exit 1; } 20 [[ $(<$out/share/fish/vendor_completions.d/foo.fish) == baz ]] || { echo "foo.fish comparison failed"; exit 1; } 21 ''
··· 13 installShellCompletion \ 14 --bash --name foo.bash <(echo foo) \ 15 --zsh --name _foo <(echo bar) \ 16 + --fish --name foo.fish <(echo baz) \ 17 + --nushell --name foo.nu <(echo bucks) 18 19 [[ $(<$out/share/bash-completion/completions/foo.bash) == foo ]] || { echo "foo.bash comparison failed"; exit 1; } 20 [[ $(<$out/share/zsh/site-functions/_foo) == bar ]] || { echo "_foo comparison failed"; exit 1; } 21 [[ $(<$out/share/fish/vendor_completions.d/foo.fish) == baz ]] || { echo "foo.fish comparison failed"; exit 1; } 22 + [[ $(<$out/share/nushell/vendor/autoload/foo.nu) == bucks ]] || { echo "foo.nu comparison failed"; exit 1; } 23 ''
+3 -1
pkgs/by-name/in/installShellFiles/tests/install-completion-inference.nix
··· 13 echo foo > foo.bash 14 echo bar > bar.zsh 15 echo baz > baz.fish 16 17 - installShellCompletion foo.bash bar.zsh baz.fish 18 19 cmp foo.bash $out/share/bash-completion/completions/foo.bash 20 cmp bar.zsh $out/share/zsh/site-functions/_bar 21 cmp baz.fish $out/share/fish/vendor_completions.d/baz.fish 22 ''
··· 13 echo foo > foo.bash 14 echo bar > bar.zsh 15 echo baz > baz.fish 16 + echo buzz > buzz.nu 17 18 + installShellCompletion foo.bash bar.zsh baz.fish buzz.nu 19 20 cmp foo.bash $out/share/bash-completion/completions/foo.bash 21 cmp bar.zsh $out/share/zsh/site-functions/_bar 22 cmp baz.fish $out/share/fish/vendor_completions.d/baz.fish 23 + cmp buzz.nu $out/share/nushell/vendor/autoload/buzz.nu 24 ''
+7 -1
pkgs/by-name/in/installShellFiles/tests/install-completion-name.nix
··· 13 echo foo > foo 14 echo bar > bar 15 echo baz > baz 16 17 - installShellCompletion --bash --name foobar.bash foo --zsh --name _foobar bar --fish baz 18 19 cmp foo $out/share/bash-completion/completions/foobar.bash 20 cmp bar $out/share/zsh/site-functions/_foobar 21 cmp baz $out/share/fish/vendor_completions.d/baz 22 ''
··· 13 echo foo > foo 14 echo bar > bar 15 echo baz > baz 16 + echo bucks > bucks 17 18 + installShellCompletion \ 19 + --bash --name foobar.bash foo \ 20 + --zsh --name _foobar bar \ 21 + --fish baz \ 22 + --nushell --name foobar.nu bucks 23 24 cmp foo $out/share/bash-completion/completions/foobar.bash 25 cmp bar $out/share/zsh/site-functions/_foobar 26 cmp baz $out/share/fish/vendor_completions.d/baz 27 + cmp bucks $out/share/nushell/vendor/autoload/foobar.nu 28 ''
+7 -1
pkgs/by-name/in/installShellFiles/tests/install-completion.nix
··· 15 echo baz > baz 16 echo qux > qux.zsh 17 echo quux > quux 18 19 - installShellCompletion --bash foo bar --zsh baz qux.zsh --fish quux 20 21 cmp foo $out/share/bash-completion/completions/foo 22 cmp bar $out/share/bash-completion/completions/bar 23 cmp baz $out/share/zsh/site-functions/_baz 24 cmp qux.zsh $out/share/zsh/site-functions/_qux 25 cmp quux $out/share/fish/vendor_completions.d/quux 26 ''
··· 15 echo baz > baz 16 echo qux > qux.zsh 17 echo quux > quux 18 + echo quokka > quokka 19 20 + installShellCompletion \ 21 + --bash foo bar \ 22 + --zsh baz qux.zsh \ 23 + --fish quux \ 24 + --nushell quokka 25 26 cmp foo $out/share/bash-completion/completions/foo 27 cmp bar $out/share/bash-completion/completions/bar 28 cmp baz $out/share/zsh/site-functions/_baz 29 cmp qux.zsh $out/share/zsh/site-functions/_qux 30 cmp quux $out/share/fish/vendor_completions.d/quux 31 + cmp quokka $out/share/nushell/vendor/autoload/quokka 32 ''