From fcbf8a08fa5c5a2b079ac81a8074c609f081b887 Mon Sep 17 00:00:00 2001 From: atagen Date: Sun, 29 Mar 2026 00:50:09 +1100 Subject: [PATCH] special case nix3 flake completions --- flake.nix | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 4cd0571..9f47cd6 100644 --- a/flake.nix +++ b/flake.nix @@ -57,8 +57,26 @@ imports = [ ./nix/module.nix ]; programs.inshellah.package = self.packages.${pkgs.stdenv.hostPlatform.system}.default; programs.inshellah.snippet = '' - let inshellah_complete = {|spans| - inshellah complete ...$spans | from json + let inshellah_complete = { |spans| + let completions = inshellah complete ...$spans | from json + # special case nix completions, for `nix run nixpkgs#..` type input + let additional = if ($completions == null and + ($spans | length) > 0 and $spans.0 == "nix") { + $env.NIX_GET_COMPLETIONS = ($spans | length) - 1 + let nix_output = $spans | run-external $in | split row -r '\n' | str trim | skip 1 + let entries = $nix_output | + if (($in | length) < 6 and + ($spans | last) =~ "[a-zA-Z][a-zA-Z0-9_-]*#[a-zA-Z][a-zA-Z0-9_-]*") { + hide-env NIX_GET_COMPLETIONS + $in | par-each { |e| { value: $e, description: (^nix eval $e --apply "f: f.meta.description") }} + } else { + $in | each { |e| { value: $e, description: "" } } + } + $entries + } else { + null + } + $completions | append $additional } $env.config.completions.external = { enable: true