kubecolor: add shell completion support

This commit is contained in:
Florian S.
2024-09-30 12:57:21 +02:00
committed by Stefan Frijters
parent 80b036a4d9
commit 994582bd5d
@@ -1,4 +1,4 @@
{ lib, buildGoModule, fetchFromGitHub }:
{ lib, stdenv, buildGoModule, fetchFromGitHub, kubectl, installShellFiles }:
buildGoModule rec {
pname = "kubecolor";
@@ -19,6 +19,26 @@ buildGoModule rec {
"."
];
nativeBuildInputs = [ installShellFiles ];
postInstall = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
# kubecolor re-uses the completions of kubectl for its own executable
installShellCompletion --cmd kubecolor \
--bash <(${lib.getExe kubectl} completion bash) \
--fish <(${lib.getExe kubectl} completion fish) \
--zsh <(${lib.getExe kubectl} completion zsh)
# https://kubecolor.github.io/setup/shells/bash/
echo 'complete -o default -F __start_kubectl kubecolor' >> $out/share/bash-completion/completions/kubecolor.bash
# https://kubecolor.github.io/setup/shells/fish/
echo -e 'function kubecolor --wraps kubectl\n command kubecolor $argv\nend' >> $out/share/fish/vendor_completions.d/kubecolor.fish
# https://kubecolor.github.io/setup/shells/zsh/
echo 'compdef kubecolor=kubectl' >> $out/share/zsh/site-functions/_kubecolor
'';
meta = with lib; {
description = "Colorizes kubectl output";
mainProgram = "kubecolor";