From 96a2cc3a5d9154fb4d4ce492b6e8c2b76f7bcf55 Mon Sep 17 00:00:00 2001 From: RGBCube Date: Wed, 13 Dec 2023 07:22:35 +0300 Subject: [PATCH] Revert "Use carapace properly" This reverts commit 8aad332ab9358fe005582dbab3d50dc2d94053e4. --- modules/nushell/configuration.nix.nu | 42 ++++++++++++++++++++++++++++ modules/nushell/default.nix | 7 +++-- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/modules/nushell/configuration.nix.nu b/modules/nushell/configuration.nix.nu index 52d091b..0ee524c 100644 --- a/modules/nushell/configuration.nix.nu +++ b/modules/nushell/configuration.nix.nu @@ -124,7 +124,49 @@ $env.config.completions = { partial: true quick: true external: { + enable: true max_results: 100 + completer: {|tokens: list| + let expanded_alias = scope aliases | where name == $tokens.0 | get --ignore-errors expansion.0 + + let tokens = if $expanded_alias != null { + $expanded_alias | split row " " | append ($tokens | skip 1) + } else { + $tokens + } + + let command = $tokens.0 | str trim --left --char "^" + + let completions = carapace $command nushell $tokens | from json | default [] + + if ($completions | is-empty) { + let path = $tokens | last + + ls $"($path)*" | each {|it| + let choice = if ($path | str ends-with "/") { + $path | path join ($it.name | path basename) + } else { + $path | path dirname | path join ($it.name | path basename) + } + + let choice = if ($it.type == "dir") and (not ($choice | str ends-with "/")) { + $"($choice)/" + } else { + $choice + } + + if ($choice | str contains " ") { + $"`($choice)`" + } else { + $choice + } + } + } else if ($completions | where value =~ "^.*ERR$" | is-empty) { + $completions + } else { + null + } + } } } diff --git a/modules/nushell/default.nix b/modules/nushell/default.nix index 09873d5..0afdd66 100644 --- a/modules/nushell/default.nix +++ b/modules/nushell/default.nix @@ -1,11 +1,10 @@ -{ config, ulib, pkgs, upkgs, theme, ... }: with ulib; merge +{ config, ulib, pkgs, upkgs, theme, ... }: with ulib; merge3 (systemConfiguration { users.defaultUserShell = pkgs.nushell; }) (homeConfiguration { - programs.carapace = enabled {}; programs.starship = enabled {}; programs.nushell = enabled { @@ -32,3 +31,7 @@ }; }; }) + +(homePackages (with pkgs; [ + carapace +]))