From 775fc350f7ef3f5a88681a862796d64a4143092d Mon Sep 17 00:00:00 2001 From: Youwen Wu Date: Wed, 16 Apr 2025 12:13:56 -0700 Subject: [PATCH] fix: nushell completions --- hm/modules/common/shellenv/config.nu | 30 +++--------- hm/modules/common/shellenv/default.nix | 64 +++++++++++++++++++------- 2 files changed, 55 insertions(+), 39 deletions(-) diff --git a/hm/modules/common/shellenv/config.nu b/hm/modules/common/shellenv/config.nu index aa6eaea..08f950b 100644 --- a/hm/modules/common/shellenv/config.nu +++ b/hm/modules/common/shellenv/config.nu @@ -1,12 +1,13 @@ let fish_completer = {|spans| - fish --command $'complete "--do-complete=($spans | str join " ")"' - | from tsv --flexible --noheaders --no-infer - | rename value description - | update value { - if ($in | path exists) {$'"($in | str replace "\"" "\\\"" )"'} else {$in} + fish --command $'complete --escape "--do-complete=($spans | str join " ")"' + | $"value(char tab)description(char newline)" + $in + | from tsv --flexible --no-infer + | each {|i| + if '\' in $i.value { + $i | merge {'value': $"\"($i.value | str replace -a '\' '')\""} + } else {$i} } } - # This completer will use fish by default let external_completer = {|spans| let expanded_alias = scope aliases @@ -28,20 +29,3 @@ let external_completer = {|spans| } $env.config.completions.external.completer = $external_completer - -def "nu-complete zoxide path" [context: string] { - let parts = $context | split row " " | skip 1 - { - options: { - sort: false - completion_algorithm: prefix - positional: false - case_sensitive: false - } - completions: (zoxide query --list --exclude $env.PWD -- ...$parts | lines) - } -} - -def --env --wrapped z [...rest: string@"nu-complete zoxide path"] { - __zoxide_z ...$rest -} diff --git a/hm/modules/common/shellenv/default.nix b/hm/modules/common/shellenv/default.nix index 211b671..eaac8b4 100644 --- a/hm/modules/common/shellenv/default.nix +++ b/hm/modules/common/shellenv/default.nix @@ -27,24 +27,55 @@ in programs.bash.enable = true; - programs.nushell = { - enable = true; - configFile.source = ./config.nu; - settings = { - show_banner = false; - completions.external = { - enable = true; - max_results = 200; + programs.nushell = + let + zoxideInit = pkgs.stdenvNoCC.mkDerivation { + inherit (pkgs.zoxide) version; + pname = "zoxide-init"; + nativeBuildInputs = [ pkgs.zoxide ]; + phases = [ "installPhase" ]; + installPhase = '' + zoxide init nushell >> $out + ''; }; - edit_mode = "vi"; - cursor_shape = { - emacs = "line"; - vi_insert = "line"; - vi_normal = "block"; + in + { + enable = true; + configFile.source = ./config.nu; + settings = { + show_banner = false; + completions.external = { + enable = true; + max_results = 200; + }; + edit_mode = "vi"; + cursor_shape = { + emacs = "line"; + vi_insert = "line"; + vi_normal = "block"; + }; }; + extraConfig = lib.mkIf config.programs.zoxide.enable '' + source "${zoxideInit}" + def "nu-complete zoxide path" [context: string] { + let parts = $context | split row " " | skip 1 + { + options: { + sort: false + completion_algorithm: prefix + positional: false + case_sensitive: false + } + completions: (zoxide query --list --exclude $env.PWD -- ...$parts | lines) + } + } + + def --env --wrapped z [...rest: string@"nu-complete zoxide path"] { + __zoxide_z ...$rest + } + ''; + plugins = with pkgs.nushellPlugins; [ polars ]; }; - plugins = with pkgs.nushellPlugins; [ polars ]; - }; programs.fzf = { enable = true; @@ -89,7 +120,8 @@ in enable = true; # we have our own fish completion plugin for zoxide enableFishIntegration = false; - enableNushellIntegration = true; + # we have our own nushell completion plugin for zoxide + enableNushellIntegration = false; enableBashIntegration = true; package = if