babashka: Install shell completions

This commit is contained in:
sohalt 2023-10-13 15:23:37 +02:00
parent a1bd79b94c
commit 808b05db11
5 changed files with 30 additions and 2 deletions

View File

@ -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

View File

@ -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'

View File

@ -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

View File

@ -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" ''

View File

@ -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 \