diff options
author | sohalt <sohalt@sohalt.net> | 2023-10-13 15:23:37 +0200 |
---|---|---|
committer | sohalt <sohalt@sohalt.net> | 2023-11-09 11:33:19 +0100 |
commit | 808b05db11b0ba4120aff70d198b4dd7b5321abe (patch) | |
tree | eaef01cd36dedad66c2bdf6b9a5ae50440f77e95 /pkgs/development | |
parent | a1bd79b94c80b812806f34da4edd233454e7375a (diff) |
babashka: Install shell completions
Diffstat (limited to 'pkgs/development')
5 files changed, 30 insertions, 2 deletions
diff --git a/pkgs/development/interpreters/babashka/completions/bb.bash b/pkgs/development/interpreters/babashka/completions/bb.bash new file mode 100644 index 0000000000000..9746fd02a0580 --- /dev/null +++ b/pkgs/development/interpreters/babashka/completions/bb.bash @@ -0,0 +1,5 @@ +_bb_tasks() { + COMPREPLY=( $(compgen -W "$(bb tasks |tail -n +3 |cut -f1 -d ' ')" -- ${COMP_WORDS[COMP_CWORD]}) ); +} +# autocomplete filenames as well +complete -f -F _bb_tasks bb diff --git a/pkgs/development/interpreters/babashka/completions/bb.fish b/pkgs/development/interpreters/babashka/completions/bb.fish new file mode 100644 index 0000000000000..36cf89fbced77 --- /dev/null +++ b/pkgs/development/interpreters/babashka/completions/bb.fish @@ -0,0 +1,9 @@ +function __bb_complete_tasks + if not test "$__bb_tasks" + set -g __bb_tasks (bb tasks |tail -n +3 |cut -f1 -d ' ') + end + + printf "%s\n" $__bb_tasks +end + +complete -c bb -a "(__bb_complete_tasks)" -d 'tasks' diff --git a/pkgs/development/interpreters/babashka/completions/bb.zsh b/pkgs/development/interpreters/babashka/completions/bb.zsh new file mode 100644 index 0000000000000..5082197405293 --- /dev/null +++ b/pkgs/development/interpreters/babashka/completions/bb.zsh @@ -0,0 +1,6 @@ +_bb_tasks() { + local matches=(`bb tasks |tail -n +3 |cut -f1 -d ' '`) + compadd -a matches + _files # autocomplete filenames as well +} +compdef _bb_tasks bb diff --git a/pkgs/development/interpreters/babashka/default.nix b/pkgs/development/interpreters/babashka/default.nix index 3b1874a605ded..dfd47994a136f 100644 --- a/pkgs/development/interpreters/babashka/default.nix +++ b/pkgs/development/interpreters/babashka/default.nix @@ -4,6 +4,7 @@ , removeReferencesTo , fetchurl , writeScript +, installShellFiles }: let @@ -20,7 +21,7 @@ let executable = "bb"; - nativeBuildInputs = [ removeReferencesTo ]; + nativeBuildInputs = [ removeReferencesTo installShellFiles ]; extraNativeImageBuildArgs = [ "-H:+ReportExceptionStackTraces" @@ -42,6 +43,9 @@ let # graalvm-ce anyway. postInstall = '' remove-references-to -t ${graalvmDrv} $out/bin/${executable} + installShellCompletion --cmd bb --bash ${./completions/bb.bash} + installShellCompletion --cmd bb --zsh ${./completions/bb.zsh} + installShellCompletion --cmd bb --fish ${./completions/bb.fish} ''; passthru.updateScript = writeScript "update-babashka" '' diff --git a/pkgs/development/interpreters/babashka/wrapped.nix b/pkgs/development/interpreters/babashka/wrapped.nix index eb03045719f0a..29468265eb9c1 100644 --- a/pkgs/development/interpreters/babashka/wrapped.nix +++ b/pkgs/development/interpreters/babashka/wrapped.nix @@ -3,6 +3,7 @@ , babashka-unwrapped , callPackage , makeWrapper +, installShellFiles , rlwrap , clojureToolsBabashka ? callPackage ./clojure-tools.nix { } , jdkBabashka ? clojureToolsBabashka.jdk @@ -23,7 +24,7 @@ stdenvNoCC.mkDerivation (finalAttrs: { dontUnpack = true; dontBuild = true; - nativeBuildInputs = [ makeWrapper ]; + nativeBuildInputs = [ makeWrapper installShellFiles ]; installPhase = let unwrapped-bin = "${babashka-unwrapped}/bin/bb"; in @@ -37,6 +38,9 @@ stdenvNoCC.mkDerivation (finalAttrs: { --set-default DEPS_CLJ_TOOLS_DIR $out/clojure_tools \ --set-default JAVA_HOME ${jdkBabashka} + installShellCompletion --cmd bb --bash ${babashka-unwrapped}/share/bash-completion/completions/bb.bash + installShellCompletion --cmd bb --zsh ${babashka-unwrapped}/share/fish/vendor_completions.d/bb.fish + installShellCompletion --cmd bb --fish ${babashka-unwrapped}/share/zsh/site-functions/_bb '' + lib.optionalString withRlwrap '' substituteInPlace $out/bin/bb \ |