Merge pull request #49477 from obsidiansystems/haskell-shell-completions

haskell-lib: Factor out shell completion scripts helper
This commit is contained in:
John Ericson
2018-10-30 15:25:03 -04:00
committed by GitHub
2 changed files with 18 additions and 7 deletions

View File

@@ -354,4 +354,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"
'';
});
}