Commit 4d1b3bdd4b28

Vincent Demeester <vincent@sbr.pm>
2025-12-04 23:06:10
feat(pkgs): add shell completion to Go and Python tools
- Improve CLI usability with bash/fish/zsh completion support - Enable tab completion for ape, manifest-tool, arr, and org-manager - Leverage native framework support (Cobra, urfave/cli, Click) Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent 2d0164b
Changed files (4)
pkgs
tools
pkgs/ape/default.nix
@@ -2,6 +2,7 @@
   lib,
   buildGoModule,
   fetchgit,
+  installShellFiles,
 }:
 
 buildGoModule rec {
@@ -16,6 +17,15 @@ buildGoModule rec {
   };
   vendorHash = "sha256-XLRjxJu28yt02+SykO8OqvFCl0nSFyVbHKRUGcS7Mrs=";
 
+  nativeBuildInputs = [ installShellFiles ];
+
+  postInstall = ''
+    installShellCompletion --cmd ape \
+      --bash <($out/bin/ape completion bash) \
+      --fish <($out/bin/ape completion fish) \
+      --zsh <($out/bin/ape completion zsh)
+  '';
+
   meta = {
     description = "a git mirror *upstream* updater ";
     homepage = "https://git.sr.ht/~vdemeester/ape";
pkgs/manifest-tool/default.nix
@@ -2,6 +2,7 @@
   lib,
   buildGoModule,
   fetchFromGitHub,
+  installShellFiles,
 }:
 
 buildGoModule rec {
@@ -21,8 +22,18 @@ buildGoModule rec {
   };
   vendorHash = null;
 
+  nativeBuildInputs = [ installShellFiles ];
+
+  postInstall = ''
+    # urfave/cli v2 shell completion support
+    installShellCompletion --cmd manifest-tool \
+      --bash <($out/bin/manifest-tool completion bash) \
+      --fish <($out/bin/manifest-tool completion fish) \
+      --zsh <($out/bin/manifest-tool completion zsh)
+  '';
+
   meta = {
-    description = "";
+    description = "Tool for inspecting and creating multi-platform container image manifests";
     homepage = "https://github.com/estesp/manifest-tool";
     license = lib.licenses.asl20;
     maintainers = with lib.maintainers; [ vdemeester ];
tools/arr/default.nix
@@ -2,6 +2,7 @@
   python3,
   lib,
   makeWrapper,
+  installShellFiles,
 }:
 
 python3.pkgs.buildPythonApplication {
@@ -11,7 +12,10 @@ python3.pkgs.buildPythonApplication {
 
   src = ./.;
 
-  nativeBuildInputs = [ makeWrapper ];
+  nativeBuildInputs = [
+    makeWrapper
+    installShellFiles
+  ];
 
   propagatedBuildInputs = with python3.pkgs; [
     click
@@ -43,6 +47,15 @@ python3.pkgs.buildPythonApplication {
       --prefix PYTHONPATH : "$out/lib/arr"
   '';
 
+  postInstall = ''
+    # Generate shell completions for click-based CLI
+    export PYTHONPATH="$out/lib/arr:$PYTHONPATH"
+    installShellCompletion --cmd arr \
+      --bash <(_ARR_COMPLETE=bash_source $out/bin/arr) \
+      --fish <(_ARR_COMPLETE=fish_source $out/bin/arr) \
+      --zsh <(_ARR_COMPLETE=zsh_source $out/bin/arr)
+  '';
+
   meta = with lib; {
     description = "Unified CLI for managing *arr services (Sonarr, Radarr, Lidarr)";
     longDescription = ''
tools/org-manager/default.nix
@@ -1,6 +1,7 @@
 {
   lib,
   buildGoModule,
+  installShellFiles,
 }:
 
 buildGoModule {
@@ -14,11 +15,20 @@ buildGoModule {
 
   vendorHash = "sha256-hocnLCzWN8srQcO3BMNkd2lt0m54Qe7sqAhUxVZlz1k=";
 
+  nativeBuildInputs = [ installShellFiles ];
+
   ldflags = [
     "-s"
     "-w"
   ];
 
+  postInstall = ''
+    installShellCompletion --cmd org-manager \
+      --bash <($out/bin/org-manager completion bash) \
+      --fish <($out/bin/org-manager completion fish) \
+      --zsh <($out/bin/org-manager completion zsh)
+  '';
+
   meta = with lib; {
     description = "Tool for managing org-mode files including backup, validation, and link checking";
     longDescription = ''