diff --git a/modules/common/nushell/config.nu b/modules/common/nushell/config.nu index 482a816..12e774b 100644 --- a/modules/common/nushell/config.nu +++ b/modules/common/nushell/config.nu @@ -3,9 +3,6 @@ use std null_device source ~/.config/nushell/zoxide.nu -$env.CARAPACE_BRIDGES = "inshellisense,carapace,zsh,fish,bash" -source ~/.config/nushell/carapace.nu - # Retrieve the output of the last command. def _ []: nothing -> any { $env.last? @@ -57,6 +54,29 @@ $env.config.completions.case_sensitive = false $env.config.completions.quick = true $env.config.completions.partial = true $env.config.completions.use_ls_colors = true +$env.config.completions.external.enable = true +$env.config.completions.external.max_results = 100 +$env.config.completions.external.completer = {|tokens: list| + let expanded = scope aliases + | where name == $tokens.0 + | get --ignore-errors 0.expansion + + mut tokens = if $expanded != null and $tokens.0 != "cd" { + $expanded | split row " " | append ($tokens | skip 1) + } else { + $tokens + } + + $tokens.0 = $tokens.0 | str trim --left --char "^" + + let command = $tokens + | str join " " + | str replace --all (char single_quote) $"\\(char single_quote)" + + fish --command $"complete '--do-complete=($command)'" + | $"value(char tab)description(char newline)" + $in + | from tsv --flexible --no-infer +} $env.config.use_kitty_protocol = true @@ -179,33 +199,19 @@ do --env { def prompt-header [ --left-char: string ]: nothing -> string { - let code = $env.LAST_EXIT_CODE - let jj_workspace_root = try { jj workspace root err> $null_device } catch { "" } - let hostname = if ($env.SSH_CONNECTION? | is-not-empty) { - let hostname = try { - hostname - } catch { - "remote" - } - - $"(ansi light_green_bold)@($hostname)(ansi reset) " - } else { - "" - } - let body = if ($jj_workspace_root | is-not-empty) { let subpath = pwd | path relative-to $jj_workspace_root let subpath = if ($subpath | is-not-empty) { $"(ansi magenta_bold) → (ansi reset)(ansi blue)($subpath)" } - $"($hostname)(ansi light_yellow_bold)($jj_workspace_root | path basename)($subpath)(ansi reset)" + $"(ansi light_yellow_bold)($jj_workspace_root | path basename)($subpath)(ansi reset)" } else { let pwd = if (pwd | str starts-with $env.HOME) { "~" | path join (pwd | path relative-to $env.HOME) @@ -213,7 +219,7 @@ do --env { pwd } - $"($hostname)(ansi cyan)($pwd)(ansi reset)" + $"(ansi cyan)($pwd)(ansi reset)" } let command_duration = ($env.CMD_DURATION_MS | into int) * 1ms @@ -223,10 +229,10 @@ do --env { $"┫(ansi light_magenta_bold)($command_duration)(ansi light_yellow_bold)┣━" } - let exit_code = if $code == 0 { + let exit_code = if $env.LAST_EXIT_CODE == 0 { "" } else { - $"┫(ansi light_red_bold)($code)(ansi light_yellow_bold)┣━" + $"┫(ansi light_red_bold)($env.LAST_EXIT_CODE)(ansi light_yellow_bold)┣━" } let middle = if $command_duration == "" and $exit_code == "" { @@ -297,7 +303,6 @@ let menus = [ layout: ide border: false correct_cursor_pos: true - max_completion_height: 25 } style: { text: white diff --git a/modules/common/nushell/default.nix b/modules/common/nushell/default.nix index 06cc79d..a010db5 100644 --- a/modules/common/nushell/default.nix +++ b/modules/common/nushell/default.nix @@ -1,5 +1,5 @@ { config, lib, pkgs, ... }: let - inherit (lib) attrValues const enabled getExe mapAttrs mkIf optionalAttrs readFile removeAttrs replaceString; + inherit (lib) attrValues const disabled enabled getExe mapAttrs mkIf optionalAttrs readFile removeAttrs replaceString; in { environment = optionalAttrs config.isLinux { sessionVariables.SHELLS = getExe pkgs.nushell; @@ -8,7 +8,6 @@ in { shellAliases = { la = "ls --all"; - ll = "ls --long"; lla = "ls --long --all"; sl = "ls"; @@ -23,12 +22,8 @@ in { systemPackages = attrValues { inherit (pkgs) - carapace # For completions. - fish # For completions. - zsh # For completions. - inshellisense # For completions. - - zoxide # For better cd. + fish # For completions. + zoxide # For completions and better cd. ; }; }; @@ -37,10 +32,6 @@ in { homeConfig = homeArgs.config; in { xdg.configFile = { - "nushell/carapace.nu".source = pkgs.runCommand "carapace.nu" {} '' - ${getExe pkgs.carapace} _carapace nushell > $out - ''; - "nushell/zoxide.nu".source = pkgs.runCommand "zoxide.nu" {} '' ${getExe pkgs.zoxide} init nushell --cmd cd > $out ''; @@ -83,6 +74,7 @@ in { shellAliases = removeAttrs config.environment.shellAliases [ "ls" "l" ] // { cdtmp = "cd (mktemp --directory)"; + ll = "ls --long"; }; }; })];