dotfiles/nushell/env.nu

136 lines
4.7 KiB
Plaintext
Raw Normal View History

2023-11-07 14:26:22 +01:00
# Nushell Environment Config File
#
# version = "0.86.0"
def create_left_prompt [] {
let home = $nu.home-path
# Perform tilde substitution on dir
# To determine if the prefix of the path matches the home dir, we split the current path into
# segments, and compare those with the segments of the home dir. In cases where the current dir
2023-11-07 15:48:00 +01:00
# is a parent of the home dir (e.g. `/home`, homedir is `/home/user`), this comparison will
2023-11-07 14:26:22 +01:00
# also evaluate to true. Inside the condition, we attempt to str replace `$home` with `~`.
# Inside the condition, either:
# 1. The home prefix will be replaced
# 2. The current dir is a parent of the home dir, so it will be uneffected by the str replace
let dir = (
if ($env.PWD | path split | zip ($home | path split) | all { $in.0 == $in.1 }) {
($env.PWD | str replace $home "~")
} else {
$env.PWD
}
)
2023-11-07 15:48:00 +01:00
# create a right prompt in magenta with green separators and am/pm underlined
let time_color = ansi magenta_bold
let time_segment = date now | format date ' [%H:%M] '
let arrow_color = ansi magenta
let first_line_arrow = "┌──"
let second_line_arrow = "└▷"
let username_color = ansi magenta_bold
let username = $env.USER
let delimiter_color = ansi yellow_bold
let first_delimiter = "@"
let second_delimiter = "::"
let hostname_color = ansi green_bold
let hostname = (sys).host.hostname
2023-11-07 14:26:22 +01:00
2023-11-07 15:48:00 +01:00
let dir_color = ansi blue_bold
let reset_ansi = ansi reset
[
$arrow_color
$first_line_arrow
$time_color
$time_segment
$username_color
$username
$delimiter_color
$first_delimiter
$hostname_color
$hostname
$delimiter_color
$second_delimiter
$dir_color
$dir
"\n"
$reset_ansi
$arrow_color
$second_line_arrow
] | str join
2023-11-07 14:26:22 +01:00
}
def create_right_prompt [] {
let last_exit_code = if ($env.LAST_EXIT_CODE != 0) {([
2023-11-07 15:48:00 +01:00
(ansi red_bold)
($env.LAST_EXIT_CODE)
" ↵ "
] | str join)
} else {([
(ansi green_bold)
2023-11-07 14:26:22 +01:00
($env.LAST_EXIT_CODE)
2023-11-07 15:48:00 +01:00
" ↵ "
2023-11-07 14:26:22 +01:00
] | str join)
2023-11-07 15:48:00 +01:00
}
2023-11-07 14:26:22 +01:00
2023-11-07 15:48:00 +01:00
([$last_exit_code] | str join)
2023-11-07 14:26:22 +01:00
}
# Use nushell functions to define your right and left prompt
$env.PROMPT_COMMAND = {|| create_left_prompt }
# FIXME: This default is not implemented in rust code as of 2023-09-08.
$env.PROMPT_COMMAND_RIGHT = {|| create_right_prompt }
# The prompt indicators are environmental variables that represent
# the state of the prompt
2023-11-07 15:48:00 +01:00
$env.PROMPT_INDICATOR = {|| " " }
2023-11-07 14:26:22 +01:00
$env.PROMPT_INDICATOR_VI_INSERT = {|| ": " }
$env.PROMPT_INDICATOR_VI_NORMAL = {|| "> " }
$env.PROMPT_MULTILINE_INDICATOR = {|| "::: " }
# If you want previously entered commands to have a different prompt from the usual one,
# you can uncomment one or more of the following lines.
# This can be useful if you have a 2-line prompt and it's taking up a lot of space
# because every command entered takes up 2 lines instead of 1. You can then uncomment
# the line below so that previously entered commands show with a single `🚀`.
# $env.TRANSIENT_PROMPT_COMMAND = {|| "🚀 " }
# $env.TRANSIENT_PROMPT_INDICATOR = {|| "" }
# $env.TRANSIENT_PROMPT_INDICATOR_VI_INSERT = {|| "" }
# $env.TRANSIENT_PROMPT_INDICATOR_VI_NORMAL = {|| "" }
# $env.TRANSIENT_PROMPT_MULTILINE_INDICATOR = {|| "" }
# $env.TRANSIENT_PROMPT_COMMAND_RIGHT = {|| "" }
# Specifies how environment variables are:
# - converted from a string to a value on Nushell startup (from_string)
# - 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) }
}
}
# Directories to search for scripts when calling source or use
$env.NU_LIB_DIRS = [
# FIXME: This default is not implemented in rust code as of 2023-09-06.
($nu.default-config-dir | path join 'scripts') # add <nushell-config-dir>/scripts
]
# Directories to search for plugin binaries when calling register
$env.NU_PLUGIN_DIRS = [
# FIXME: This default is not implemented in rust code as of 2023-09-06.
($nu.default-config-dir | path join 'plugins') # add <nushell-config-dir>/plugins
]
# To add entries to PATH (on Windows you might use Path), you can use the following pattern:
# $env.PATH = ($env.PATH | split row (char esep) | prepend '/some/path')