summary refs log tree commit diff
path: root/pkgs/development/haskell-modules
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2018-10-30 14:20:24 -0400
committerJohn Ericson <John.Ericson@Obsidian.Systems>2018-10-30 14:49:58 -0400
commitc34f5176f1173ac2cdaeed4512a61389d98f9d9f (patch)
treed777bd7d3097c3caca4f3069995c8db9425d4edf /pkgs/development/haskell-modules
parent88cd633ea4dec7b9a247c0fd8ccb95f4982f5bf7 (diff)
downloadnixlib-c34f5176f1173ac2cdaeed4512a61389d98f9d9f.tar
nixlib-c34f5176f1173ac2cdaeed4512a61389d98f9d9f.tar.gz
nixlib-c34f5176f1173ac2cdaeed4512a61389d98f9d9f.tar.bz2
nixlib-c34f5176f1173ac2cdaeed4512a61389d98f9d9f.tar.lz
nixlib-c34f5176f1173ac2cdaeed4512a61389d98f9d9f.tar.xz
nixlib-c34f5176f1173ac2cdaeed4512a61389d98f9d9f.tar.zst
nixlib-c34f5176f1173ac2cdaeed4512a61389d98f9d9f.zip
haskell-lib: Factor out shell completion scripts helper
Diffstat (limited to 'pkgs/development/haskell-modules')
-rw-r--r--pkgs/development/haskell-modules/lib.nix15
1 files changed, 15 insertions, 0 deletions
diff --git a/pkgs/development/haskell-modules/lib.nix b/pkgs/development/haskell-modules/lib.nix
index 8dae7c8d72c0..10edf69478b0 100644
--- a/pkgs/development/haskell-modules/lib.nix
+++ b/pkgs/development/haskell-modules/lib.nix
@@ -407,4 +407,19 @@ rec {
 
       in
         builtins.listToAttrs (map toKeyVal haskellPaths);
+
+  # Modify a Haskell package to add completion scripts for the given executable
+  # produced by it. These completion scripts will be picked up automatically if
+  # the resulting derivation is installed, e.g. by `nix-env -i`.
+  addOptparseApplicativeCompletionScripts = exeName: pkg: overrideCabal pkg (drv: {
+    postInstall = (drv.postInstall or "") + ''
+      bashCompDir="$out/share/bash-completion/completions"
+      zshCompDir="$out/share/zsh/vendor-completions"
+      fishCompDir="$out/share/fish/vendor_completions.d"
+      mkdir -p "$bashCompDir" "$zshCompDir" "$fishCompDir"
+      "$out/bin/${exeName}" --bash-completion-script "$out/bin/${exeName}" >"$bashCompDir/${exeName}"
+      "$out/bin/${exeName}" --zsh-completion-script "$out/bin/${exeName}" >"$zshCompDir/_${exeName}"
+      "$out/bin/${exeName}" --fish-completion-script "$out/bin/${exeName}" >"$fishCompDir/${exeName}.fish"
+    '';
+  });
 }