From c9a710b86b6af740b653440a22e3cf36a6f91ae1 Mon Sep 17 00:00:00 2001 From: Joakim Hulthe Date: Mon, 4 Nov 2024 17:14:22 +0100 Subject: [PATCH] nushell: Small fixes --- tree/.config/nushell/config.nu | 7 +++ tree/.config/nushell/env.nu | 90 ++++++++++++++++++---------------- 2 files changed, 54 insertions(+), 43 deletions(-) diff --git a/tree/.config/nushell/config.nu b/tree/.config/nushell/config.nu index bb7f43f..3f06113 100644 --- a/tree/.config/nushell/config.nu +++ b/tree/.config/nushell/config.nu @@ -30,6 +30,13 @@ source theme.nu $env.config = { show_banner: false + display_errors: { + exit_code: false # assume the external command prints an error message + # Core dump errors are always printed, and SIGPIPE never triggers an error. + # The setting below controls message printing for termination by all other signals. + termination_signal: true + } + ls: { use_ls_colors: true # use the LS_COLORS environment variable to colorize output clickable_links: true # enable or disable clickable links. Your terminal has to support links. diff --git a/tree/.config/nushell/env.nu b/tree/.config/nushell/env.nu index 9281ed9..8cd7612 100644 --- a/tree/.config/nushell/env.nu +++ b/tree/.config/nushell/env.nu @@ -3,43 +3,43 @@ # version = 0.83.1 def create_left_prompt [] { - mut home = "" - try { - if $nu.os-info.name == "windows" { - $home = $env.USERPROFILE - } else { - $home = $env.HOME - } - } + mut home = "" + try { + if $nu.os-info.name == "windows" { + $home = $env.USERPROFILE + } else { + $home = $env.HOME + } + } - let dir = ([ - ($env.PWD | str substring 0..($home | str length) | str replace $home "~"), - ($env.PWD | str substring ($home | str length)..) - ] | str join) + let dir = ([ + ($env.PWD | str substring 0..($home | str length) | str replace $home "~"), + ($env.PWD | str substring ($home | str length)..) + ] | str join) - let path_color = (if (is-admin) { ansi red_bold } else { ansi green_bold }) - let separator_color = (if (is-admin) { ansi light_red_bold } else { ansi light_green_bold }) - let path_segment = $"($path_color)($dir)" + let path_color = (if (is-admin) { ansi red_bold } else { ansi green_bold }) + let separator_color = (if (is-admin) { ansi light_red_bold } else { ansi light_green_bold }) + let path_segment = $"($path_color)($dir)" - $path_segment | str replace --all (char path_sep) $"($separator_color)/($path_color)" + $path_segment | str replace --all (char path_sep) $"($separator_color)/($path_color)" } def create_right_prompt [] { - # create a right prompt in magenta with green separators and am/pm underlined - let time_segment = ([ - (ansi reset) - (ansi magenta) - (date now | date format '%Y/%m/%d %r') - ] | str join | str replace --all "([/:])" $"(ansi green)${1}(ansi magenta)" | - str replace --all "([AP]M)" $"(ansi magenta_underline)${1}") + # create a right prompt in magenta with green separators and am/pm underlined + let time_segment = ([ + (ansi reset) + (ansi magenta) + (date now | date format '%Y/%m/%d %r') + ] | str join | str replace --all "([/:])" $"(ansi green)${1}(ansi magenta)" | + str replace --all "([AP]M)" $"(ansi magenta_underline)${1}") - let last_exit_code = if ($env.LAST_EXIT_CODE != 0) {([ - (ansi rb) - ($env.LAST_EXIT_CODE) - ] | str join) - } else { "" } + let last_exit_code = if ($env.LAST_EXIT_CODE != 0) {([ + (ansi rb) + ($env.LAST_EXIT_CODE) + ] | str join) + } else { "" } - ([$last_exit_code, (char space), $time_segment] | str join) + ([$last_exit_code, (char space), $time_segment] | str join) } # Use nushell functions to define your right and left prompt @@ -58,31 +58,35 @@ $env.PROMPT_MULTILINE_INDICATOR = {|| "::: " } # - converted from a value back to a string when running external commands (to_string) # Note: The conversions happen *after* config.nu is loaded $env.ENV_CONVERSIONS = { - "PATH": { - from_string: { |s| $s | split row (char esep) | path expand --no-symlink } - to_string: { |v| $v | path expand --no-symlink | str join (char esep) } - } - "Path": { - from_string: { |s| $s | split row (char esep) | path expand --no-symlink } - to_string: { |v| $v | path expand --no-symlink | str join (char esep) } - } + "PATH": { + from_string: { |s| $s | split row (char esep) | path expand --no-symlink } + to_string: { |v| $v | path expand --no-symlink | str join (char esep) } + } + "Path": { + from_string: { |s| $s | split row (char esep) | path expand --no-symlink } + to_string: { |v| $v | path expand --no-symlink | str join (char esep) } + } } # Directories to search for scripts when calling source or use $env.NU_LIB_DIRS = [ - # ($nu.default-config-dir | path join 'scripts') # add /scripts + # ($nu.default-config-dir | path join 'scripts') # add /scripts ] # Directories to search for plugin binaries when calling register $env.NU_PLUGIN_DIRS = [ - # ($nu.default-config-dir | path join 'plugins') # add /plugins + # ($nu.default-config-dir | path join 'plugins') # add /plugins ] +if XDG_CONFIG_HOME not-in $env { + $env.XDG_CONFIG_HOME = $"($env.HOME)/.config" +} + $env.PATH = ($env.PATH | split row (char esep) | prepend [ - ($env.HOME + "/.local/bin"), - ($env.HOME + "/.cargo/bin"), - ($env.HOME + "/.radicle/bin"), - ($env.HOME + "/.volta/bin"), + ($env.HOME + "/.local/bin"), + ($env.HOME + "/.cargo/bin"), + ($env.HOME + "/.radicle/bin"), + ($env.HOME + "/.volta/bin"), ]) # auto-detect which ssh-agent to use