diff --git a/pkgs/development/interpreters/babashka/completions/bb.bash b/pkgs/development/interpreters/babashka/completions/bb.bash new file mode 100644 index 000000000000..9746fd02a058 --- /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 000000000000..36cf89fbced7 --- /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 000000000000..508219740529 --- /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 3b1874a605de..dfd47994a136 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 eb03045719f0..29468265eb9c 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 \