From 8c3ff343b065b60352ae52f9a3064d647f658dde Mon Sep 17 00:00:00 2001 From: Bloxx12 Date: Mon, 21 Jul 2025 00:05:24 +0200 Subject: [PATCH] nushell: move to modules/home Signed-off-by: Bloxx12 Change-Id: I6a6a6964b332aee4de78ddbba4d16b55f6783485 --- flake.nix | 1 - modules/home/nushell/completions.nu | 1 + {packages => modules/home}/nushell/config.nu | 110 +++++++++++++++++-- modules/home/nushell/nu.hjem.nix | 22 ++++ {packages => modules/home}/nushell/prompt.nu | 0 modules/home/nushell/zoxide.nu | 54 +++++++++ modules/other/users.mod.nix | 9 +- packages/default.nix | 2 - packages/nushell/default.nix | 47 -------- packages/nushell/packages.nix | 65 ----------- 10 files changed, 183 insertions(+), 128 deletions(-) create mode 100644 modules/home/nushell/completions.nu rename {packages => modules/home}/nushell/config.nu (56%) create mode 100644 modules/home/nushell/nu.hjem.nix rename {packages => modules/home}/nushell/prompt.nu (100%) create mode 100644 modules/home/nushell/zoxide.nu delete mode 100644 packages/nushell/default.nix delete mode 100644 packages/nushell/packages.nix diff --git a/flake.nix b/flake.nix index c11970d..a2d99c2 100644 --- a/flake.nix +++ b/flake.nix @@ -26,7 +26,6 @@ }) fish kakoune - nushell ; }) pkgsFor; devShells = lib.mapAttrs (_: pkgs: { diff --git a/modules/home/nushell/completions.nu b/modules/home/nushell/completions.nu new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/modules/home/nushell/completions.nu @@ -0,0 +1 @@ + diff --git a/packages/nushell/config.nu b/modules/home/nushell/config.nu similarity index 56% rename from packages/nushell/config.nu rename to modules/home/nushell/config.nu index 076e8ad..7ffcf43 100644 --- a/packages/nushell/config.nu +++ b/modules/home/nushell/config.nu @@ -24,6 +24,102 @@ $env.config = { } } +$env.config.color_config = { + binary: '#b48ead' + block: '#81a1c1' + cell-path: '#e5e9f0' + closure: '#88c0d0' + custom: '#8fbcbb' + duration: '#ebcb8b' + float: '#bf616a' + glob: '#8fbcbb' + int: '#b48ead' + list: '#88c0d0' + nothing: '#bf616a' + range: '#ebcb8b' + record: '#88c0d0' + string: '#a3be8c' + + bool: {|| if $in { '#88c0d0' } else { '#ebcb8b' } } + + datetime: {|| (date now) - $in | + if $in < 1hr { + { fg: '#bf616a' attr: 'b' } + } else if $in < 6hr { + '#bf616a' + } else if $in < 1day { + '#ebcb8b' + } else if $in < 3day { + '#a3be8c' + } else if $in < 1wk { + { fg: '#a3be8c' attr: 'b' } + } else if $in < 6wk { + '#88c0d0' + } else if $in < 52wk { + '#81a1c1' + } else { 'dark_gray' } + } + + filesize: {|e| + if $e == 0b { + '#e5e9f0' + } else if $e < 1mb { + '#88c0d0' + } else {{ fg: '#81a1c1' }} + } + + shape_and: { fg: '#b48ead' attr: 'b' } + shape_binary: { fg: '#b48ead' attr: 'b' } + shape_block: { fg: '#81a1c1' attr: 'b' } + shape_bool: '#88c0d0' + shape_closure: { fg: '#88c0d0' attr: 'b' } + shape_custom: '#a3be8c' + shape_datetime: { fg: '#88c0d0' attr: 'b' } + shape_directory: '#88c0d0' + shape_external: '#88c0d0' + shape_external_resolved: '#88c0d0' + shape_externalarg: { fg: '#a3be8c' attr: 'b' } + shape_filepath: '#88c0d0' + shape_flag: { fg: '#81a1c1' attr: 'b' } + shape_float: { fg: '#bf616a' attr: 'b' } + shape_garbage: { fg: '#FFFFFF' bg: '#FF0000' attr: 'b' } + shape_glob_interpolation: { fg: '#88c0d0' attr: 'b' } + shape_globpattern: { fg: '#88c0d0' attr: 'b' } + shape_int: { fg: '#b48ead' attr: 'b' } + shape_internalcall: { fg: '#88c0d0' attr: 'b' } + shape_keyword: { fg: '#b48ead' attr: 'b' } + shape_list: { fg: '#88c0d0' attr: 'b' } + shape_literal: '#81a1c1' + shape_match_pattern: '#a3be8c' + shape_matching_brackets: { attr: 'u' } + shape_nothing: '#bf616a' + shape_operator: '#ebcb8b' + shape_or: { fg: '#b48ead' attr: 'b' } + shape_pipe: { fg: '#b48ead' attr: 'b' } + shape_range: { fg: '#ebcb8b' attr: 'b' } + shape_raw_string: { fg: '#8fbcbb' attr: 'b' } + shape_record: { fg: '#88c0d0' attr: 'b' } + shape_redirection: { fg: '#b48ead' attr: 'b' } + shape_signature: { fg: '#a3be8c' attr: 'b' } + shape_string: '#a3be8c' + shape_string_interpolation: { fg: '#88c0d0' attr: 'b' } + shape_table: { fg: '#81a1c1' attr: 'b' } + shape_vardecl: { fg: '#81a1c1' attr: 'u' } + shape_variable: '#b48ead' + + foreground: '#e5e9f0' + background: '#2e3440' + cursor: '#e5e9f0' + + empty: '#81a1c1' + header: { fg: '#a3be8c' attr: 'b' } + hints: '#4c566a' + leading_trailing_space_bg: { attr: 'n' } + row_index: { fg: '#a3be8c' attr: 'b' } + search_result: { fg: '#bf616a' bg: '#e5e9f0' } + separator: '#e5e9f0' +} + $env.config.ls = { clickable_links: true use_ls_colors: true @@ -111,7 +207,7 @@ let menus = [ { name: completion_menu only_buffer_difference: false - marker: "(ansi yellow)╋ " + marker: $"(ansi yellow)╋ " type: { layout: ide min_completion_width: 0 @@ -195,12 +291,10 @@ def switch [] { # fix sudo by prepending /run/wrappers/bin to the PATH. $env.PATH = ($env.PATH | split row (char esep) | prepend '/run/wrappers/bin') +$env.PATH = ($env.PATH | split row (char esep) | prepend '/etc/profiles/per-user/cr/bin') -$env.CARAPACE_BRIDGES = 'inshellisense,fish,carapace,clap,bash' -$env.CARAPACE_MATCH = 1 +carapace _carapace nushell +| save -f ($nu.user-autoload-dirs | path join carapace.nu) -# Set environment variables according to the path of the clone -$env.TOPIARY_CONFIG_FILE = ($env.HOME | path join .config | path join topiary languages.ncl) -$env.TOPIARY_LANGUAGE_DIR = ($env.HOME | path join .config | path join topiary languages) -# The prompt indicators are environmental variables that represent -# the state of the prompt. +source ./prompt.nu +source ./zoxide.nu diff --git a/modules/home/nushell/nu.hjem.nix b/modules/home/nushell/nu.hjem.nix new file mode 100644 index 0000000..6ffa828 --- /dev/null +++ b/modules/home/nushell/nu.hjem.nix @@ -0,0 +1,22 @@ +{ + pkgs, + ... +}: +{ + + packages = with pkgs; [ + nushell + inshellisense + carapace + ]; + environment.sessionVariables = { + CARAPACE_BRIDGES = "inshellisense,carapace,clap,bash"; + CARAPACE_MATCH = 1; + }; + + files = { + ".config/nushell/config.nu".source = ./config.nu; + ".config/nushell/prompt.nu".source = ./prompt.nu; + ".config/nushell/zoxide.nu".source = ./zoxide.nu; + }; +} diff --git a/packages/nushell/prompt.nu b/modules/home/nushell/prompt.nu similarity index 100% rename from packages/nushell/prompt.nu rename to modules/home/nushell/prompt.nu diff --git a/modules/home/nushell/zoxide.nu b/modules/home/nushell/zoxide.nu new file mode 100644 index 0000000..a2bf5d7 --- /dev/null +++ b/modules/home/nushell/zoxide.nu @@ -0,0 +1,54 @@ +# Initialize hook to add new entries to the database. +export-env { + $env.config = ( + $env.config? + | default {} + | upsert hooks { default {} } + | upsert hooks.env_change { default {} } + | upsert hooks.env_change.PWD { default [] } + ) + let __zoxide_hooked = ( + $env.config.hooks.env_change.PWD | any { try { get __zoxide_hook } catch { false } } + ) + if not $__zoxide_hooked { + $env.config.hooks.env_change.PWD = ($env.config.hooks.env_change.PWD | append { + __zoxide_hook: true, + code: {|_, dir| zoxide add -- $dir} + }) + } +} + +def zoxide_completions [context: string] { + let parts = $context | split row " " | skip 1 + { + options: { + sort: false, + completion_algorithm: substring, + case_sensitive: false, + }, + completions: (^zoxide query --list --exclude $env.PWD -- ...$parts | lines | first 10) + } +} + +# Jump to a directory using only keywords. +def --env --wrapped __zoxide_z [...rest: string@zoxide_completions] { + let path = match $rest { + [] => {'~'}, + [ '-' ] => {'-'}, + [ $arg ] if ($arg | path expand | path type) == 'dir' => {$arg} + _ => { + zoxide query --exclude $env.PWD -- ...$rest | str trim -r -c "\n" + } + } + cd $path +} + +# Jump to a directory using interactive search. +def --env --wrapped __zoxide_zi [...rest:string] { + cd $'(zoxide query --interactive -- ...$rest | str trim -r -c "\n")' +} + +# ============================================================================= +alias z = __zoxide_z +alias zi = __zoxide_zi + diff --git a/modules/other/users.mod.nix b/modules/other/users.mod.nix index 040ef2a..1189e55 100644 --- a/modules/other/users.mod.nix +++ b/modules/other/users.mod.nix @@ -2,7 +2,7 @@ config, lib, pkgs, - self, + sources, ... }: let @@ -10,10 +10,9 @@ let inherit (lib.options) mkOption; inherit (lib.types) listOf str package; inherit (config.meta.mainUser) username; - - nushell = pkgs.callPackage (self + "/packages/nushell") { }; in { + imports = [ (sources.hjem + "/modules/nixos") ]; options.meta = { users = mkOption { type = listOf str; @@ -52,7 +51,7 @@ in }; package = mkOption { type = package; - default = nushell; + default = pkgs.nushell; }; }; }; @@ -72,7 +71,7 @@ in "nix" "docker" ]; - shell = nushell; + shell = pkgs.nushell; }; }; }; diff --git a/packages/default.nix b/packages/default.nix index b3ee780..bacd417 100644 --- a/packages/default.nix +++ b/packages/default.nix @@ -7,12 +7,10 @@ let inherit (pkgs) lib; kakoune = pkgs.callPackage ./kakoune.nix { }; fish = pkgs.callPackage ./fish { inherit lib; }; - nushell = pkgs.callPackage ./nushell { }; in { inherit kakoune fish - nushell ; } diff --git a/packages/nushell/default.nix b/packages/nushell/default.nix deleted file mode 100644 index d01a589..0000000 --- a/packages/nushell/default.nix +++ /dev/null @@ -1,47 +0,0 @@ -{ pkgs, ... }: -let - inherit (pkgs) lib; - inherit (lib.meta) getExe; - - nu-config = - pkgs.writeText "nu-init" - # nu - '' - #!/usr/bin/env nu - source ${./config.nu} - source ${./prompt.nu} - - let autoload_dir = $nu.user-autoload-dirs.0 - mkdir $autoload_dir - - let zoxide_path = $autoload_dir | path join zoxide.nu - if not ($zoxide_path | path exists) { - ${getExe pkgs.zoxide} init nushell --cmd cd | save -f $zoxide_path - } - # Atuin is too slow, sadly. - # let atuin_path = $autoload_dir | path join atuin.nu - # if not ($atuin_path | path exists) { - # ${getExe pkgs.atuin} init nu | save -f $atuin_path - # } - let carapace_path = $autoload_dir | path join carapace.nu - if not ($carapace_path | path exists) { - ${getExe pkgs.carapace} _carapace nushell | save -f $carapace_path - } - ''; - packages = import ./packages.nix pkgs; -in -(pkgs.symlinkJoin { - name = "nushell"; - paths = [ pkgs.nushell ] ++ packages; - nativeBuildInputs = [ pkgs.makeWrapper ]; - postBuild = '' - wrapProgram $out/bin/nu --add-flags "\ - --config ${nu-config}" - ''; -}).overrideAttrs - (_: { - passthru = { - shellPath = "/bin/nu"; - }; - meta.mainProgram = "nu"; - }) diff --git a/packages/nushell/packages.nix b/packages/nushell/packages.nix deleted file mode 100644 index cea8418..0000000 --- a/packages/nushell/packages.nix +++ /dev/null @@ -1,65 +0,0 @@ -pkgs: -builtins.attrValues { - inherit (pkgs) - # better cd - zoxide - # pipe viewer - pv - # hex editor - bvi - #better ls - eza - atuin - # better cat - bat - # clipboard - # yazi - serpl - diff-so-fancy - tig - direnv - sesh - mprocs - curlie - entr - procs - sd - # mult - glow - # dua-cli - dust - kondo - # better grep - ripgrep - # IP stuff - dig - # simply the best fetch tool out there - microfetch - fzf - element - difftastic - hexyl - yazi - gnumake - asciinema - inetutils - tokei - starship - wget - cpufetch - watchman - tealdeer - hyperfine - imagemagick - ffmpeg-full - timg - nmap - fd - jq - rsync - figlet - unzip - zip - ouch - ; -}