about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPol Dellaiera <pol.dellaiera@protonmail.com>2024-06-16 22:11:36 +0200
committerGitHub <noreply@github.com>2024-06-16 22:11:36 +0200
commit1ba3c9f006d3201f2eb601fcb7d85a91e97da3ea (patch)
tree1c06a509f7614a90147f118fffbf815df0ee58d1
parentdc7903bf42f738d0c254158e152ab881ab37f365 (diff)
parentb331e60725f6608ef66d1e858e0943ea33316833 (diff)
Merge pull request #320124 from maxbrunet/feat/pnpm/shell-completion
pnpm: install shell completions
-rw-r--r--pkgs/development/tools/pnpm/generic.nix22
1 files changed, 22 insertions, 0 deletions
diff --git a/pkgs/development/tools/pnpm/generic.nix b/pkgs/development/tools/pnpm/generic.nix
index 5560f4aee6ebc..7050df4489709 100644
--- a/pkgs/development/tools/pnpm/generic.nix
+++ b/pkgs/development/tools/pnpm/generic.nix
@@ -3,6 +3,7 @@
   stdenvNoCC,
   callPackages,
   fetchurl,
+  installShellFiles,
   nodejs,
   testers,
   withNode ? true,
@@ -25,6 +26,8 @@
 
   buildInputs = lib.optionals withNode [ nodejs ];
 
+  nativeBuildInputs = [ installShellFiles nodejs ];
+
   installPhase = ''
     runHook preInstall
 
@@ -36,6 +39,25 @@
     runHook postInstall
   '';
 
+  postInstall =
+    if lib.toInt (lib.versions.major version) < 9 then ''
+      export HOME="$PWD"
+      node $out/bin/pnpm install-completion bash
+      node $out/bin/pnpm install-completion fish
+      node $out/bin/pnpm install-completion zsh
+      sed -i '1 i#compdef pnpm' .config/tabtab/zsh/pnpm.zsh
+      installShellCompletion \
+        .config/tabtab/bash/pnpm.bash \
+        .config/tabtab/fish/pnpm.fish \
+        .config/tabtab/zsh/pnpm.zsh
+    '' else ''
+      node $out/bin/pnpm completion bash >pnpm.bash
+      node $out/bin/pnpm completion fish >pnpm.fish
+      node $out/bin/pnpm completion zsh >pnpm.zsh
+      sed -i '1 i#compdef pnpm' pnpm.zsh
+      installShellCompletion pnpm.{bash,fish,zsh}
+    '';
+
   passthru = let
     fetchDepsAttrs = callPackages ./fetch-deps { pnpm = finalAttrs.finalPackage; };
   in {