From 3ec7f3f0de20c9136c00a4d8ca8673a3dc830514 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Tue, 4 Aug 2020 21:47:05 +0200 Subject: [PATCH] feat(dhall-*): add zsh and fish completions Uses the new optparse-applicative support for fish and zsh, and the nixpkgs `installShellCompletion` hook to automatically put the completions in the right directories. --- build.nix | 10 ++++++++-- dhall-json-simple.nix | 24 ++++++++++++++++++++---- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/build.nix b/build.nix index 518f34a..1575ef2 100644 --- a/build.nix +++ b/build.nix @@ -19,12 +19,18 @@ pkgs.stdenv.mkDerivation rec { sha256 = release.${"${attrName}-linux"}.hash; }; + nativeBuildInputs = [ pkgs.installShellFiles ]; + installPhase = '' mkdir -p $out/bin binPath="$out/bin/${binName}" install -D -m555 -T ${binName} "$binPath" - mkdir -p $out/etc/bash_completion.d/ - "$binPath" --bash-completion-script "$binPath" > "$out/etc/bash_completion.d/${binName}-completion.bash" + "$binPath" --bash-completion-script "$binPath" > "${binName}.bash" + installShellCompletion --bash "${binName}.bash" + "$binPath" --zsh-completion-script "$binPath" > "${binName}.zsh" + installShellCompletion --zsh "${binName}.zsh" + "$binPath" --fish-completion-script "$binPath" > "${binName}.fish" + installShellCompletion --fish "${binName}.fish" ''; } diff --git a/dhall-json-simple.nix b/dhall-json-simple.nix index 9992f0d..bb99ba7 100644 --- a/dhall-json-simple.nix +++ b/dhall-json-simple.nix @@ -17,6 +17,8 @@ pkgs.stdenv.mkDerivation rec { sha256 = release.dhall-json-linux.hash; }; + nativeBuildInputs = [ pkgs.installShellFiles ]; + installPhase = '' mkdir -p $out/bin DHALL_TO_JSON=$out/bin/dhall-to-json @@ -26,9 +28,23 @@ pkgs.stdenv.mkDerivation rec { install -D -m555 -T dhall-to-yaml $DHALL_TO_YAML install -D -m555 -T json-to-dhall $JSON_TO_DHALL - mkdir -p $out/etc/bash_completion.d/ - $DHALL_TO_JSON --bash-completion-script $DHALL_TO_JSON > $out/etc/bash_completion.d/dhall-to-json-completion.bash - $DHALL_TO_YAML --bash-completion-script $DHALL_TO_YAML > $out/etc/bash_completion.d/dhall-to-yaml-completion.bash - $JSON_TO_DHALL --bash-completion-script $JSON_TO_DHALL > $out/etc/bash_completion.d/json-to-dhall-completion.bash + "$DHALL_TO_JSON" --bash-completion-script "$DHALL_TO_JSON" > "dhall-to-json.bash" + "$DHALL_TO_YAML" --bash-completion-script "$DHALL_TO_YAML" > "dhall-to-yaml.bash" + "$JSON_TO_DHALL" --bash-completion-script "$JSON_TO_DHALL" > "json-to-dhall.bash" + installShellCompletion --bash "dhall-to-json.bash" + installShellCompletion --bash "dhall-to-yaml.bash" + installShellCompletion --bash "json-to-dhall.bash" + "$DHALL_TO_JSON" --zsh-completion-script "$DHALL_TO_JSON" > "dhall-to-json.zsh" + "$DHALL_TO_YAML" --zsh-completion-script "$DHALL_TO_YAML" > "dhall-to-yaml.zsh" + "$JSON_TO_DHALL" --zsh-completion-script "$JSON_TO_DHALL" > "json-to-dhall.zsh" + installShellCompletion --zsh "dhall-to-json.zsh" + installShellCompletion --zsh "dhall-to-yaml.zsh" + installShellCompletion --zsh "json-to-dhall.zsh" + "$DHALL_TO_JSON" --fish-completion-script "$DHALL_TO_JSON" > "dhall-to-json.fish" + "$DHALL_TO_YAML" --fish-completion-script "$DHALL_TO_YAML" > "dhall-to-yaml.fish" + "$JSON_TO_DHALL" --fish-completion-script "$JSON_TO_DHALL" > "json-to-dhall.fish" + installShellCompletion --fish "dhall-to-json.fish" + installShellCompletion --fish "dhall-to-yaml.fish" + installShellCompletion --fish "json-to-dhall.fish" ''; }