3
0
Fork 0
forked from mirrors/nixpkgs

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

haskell-lib: Factor out shell completion scripts helper for 18.09
This commit is contained in:
John Ericson 2018-10-30 15:25:06 -04:00 committed by GitHub
commit 5fe3360114
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 7 deletions

View file

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

View file

@ -1006,10 +1006,10 @@ with pkgs;
cue2pops = callPackage ../tools/cd-dvd/cue2pops { };
cabal2nix = haskell.lib.overrideCabal haskellPackages.cabal2nix (drv: {
cabal2nix = haskell.lib.overrideCabal (haskell.lib.addOptparseApplicativeCompletionScripts "cabal2nix" haskellPackages.cabal2nix) (drv: {
isLibrary = false;
enableSharedExecutables = false;
executableToolDepends = [ makeWrapper ];
executableToolDepends = (drv.executableToolDepends or []) ++ [ makeWrapper ];
postInstall = ''
exe=$out/libexec/${drv.pname}-${drv.version}/${drv.pname}
install -D $out/bin/${drv.pname} $exe
@ -1017,11 +1017,7 @@ with pkgs;
makeWrapper $exe $out/bin/${drv.pname} \
--prefix PATH ":" "${nix}/bin" \
--prefix PATH ":" "${nix-prefetch-scripts}/bin"
mkdir -p $out/share/{bash-completion/completions,zsh/vendor-completions,fish/completions}
$exe --bash-completion-script $exe >$out/share/bash-completion/completions/${drv.pname}
$exe --zsh-completion-script $exe >$out/share/zsh/vendor-completions/_${drv.pname}
$exe --fish-completion-script $exe >$out/share/fish/completions/${drv.pname}.fish
'';
'' + (drv.postInstall or "");
});
stack2nix = with haskell.lib; overrideCabal (justStaticExecutables haskellPackages.stack2nix) (drv: {