summary refs log tree commit diff
path: root/pkgs/development
diff options
context:
space:
mode:
authorThiago Kenji Okada <thiagokokada@gmail.com>2023-11-09 13:03:01 +0000
committerGitHub <noreply@github.com>2023-11-09 13:03:01 +0000
commita75a35caa828ade854fdf0623c86e3fd7c4462e2 (patch)
tree07e45cbcae85857eafc167f83491970ac380b11b /pkgs/development
parent1ea3b8a8910ca6025a9389add0ffeb43d8525cf3 (diff)
parent808b05db11b0ba4120aff70d198b4dd7b5321abe (diff)
downloadnixpkgs-a75a35caa828ade854fdf0623c86e3fd7c4462e2.tar
nixpkgs-a75a35caa828ade854fdf0623c86e3fd7c4462e2.tar.gz
nixpkgs-a75a35caa828ade854fdf0623c86e3fd7c4462e2.tar.bz2
nixpkgs-a75a35caa828ade854fdf0623c86e3fd7c4462e2.tar.lz
nixpkgs-a75a35caa828ade854fdf0623c86e3fd7c4462e2.tar.xz
nixpkgs-a75a35caa828ade854fdf0623c86e3fd7c4462e2.tar.zst
nixpkgs-a75a35caa828ade854fdf0623c86e3fd7c4462e2.zip
Merge pull request #262232 from Sohalt/babashka-completions
babashka: Install shell completions
Diffstat (limited to 'pkgs/development')
-rw-r--r--pkgs/development/interpreters/babashka/completions/bb.bash5
-rw-r--r--pkgs/development/interpreters/babashka/completions/bb.fish9
-rw-r--r--pkgs/development/interpreters/babashka/completions/bb.zsh6
-rw-r--r--pkgs/development/interpreters/babashka/default.nix6
-rw-r--r--pkgs/development/interpreters/babashka/wrapped.nix6
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 00000000000..9746fd02a05
--- /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 00000000000..36cf89fbced
--- /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 00000000000..50821974052
--- /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 ef9636e12de..f160cf6de63 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 eb03045719f..29468265eb9 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 \