dotfiles/nushell/env.nu

254 lines
7.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 23:41:30 +01:00
# Arrow of prompt
let arrow_color = if "SSH_CLIENT" in $env {
ansi green_bold
} else {
ansi magenta_bold
}
2023-11-07 15:48:00 +01:00
let first_line_arrow = "┌──"
let second_line_arrow = "└▷"
2023-11-07 23:41:30 +01:00
# Time
let time_color = ansi magenta_bold
let time_segment = date now | format date ' [%H:%M] '
# Name of the current user
2023-11-07 15:48:00 +01:00
let username_color = ansi magenta_bold
let username = $env.USER
2023-11-07 23:41:30 +01:00
# Delimiter between user and hostname, then hostname and cwd
2023-11-07 15:48:00 +01:00
let delimiter_color = ansi yellow_bold
let first_delimiter = "@"
let second_delimiter = "::"
2023-11-07 23:41:30 +01:00
# Hostname
2023-11-07 15:48:00 +01:00
let hostname_color = ansi green_bold
let hostname = (sys).host.hostname
2023-11-07 14:26:22 +01:00
2023-11-07 23:41:30 +01:00
# Current director
2023-11-07 15:48:00 +01:00
let dir_color = ansi blue_bold
let reset_ansi = ansi reset
2023-11-07 23:41:30 +01:00
# Current git branch, with * if things are not commited
2023-11-07 17:53:57 +01:00
let git_color = [(ansi reset), (ansi yellow)] | str join
let git_branch = do { git rev-parse --abbrev-ref HEAD }
| complete
2023-11-08 16:55:17 +01:00
| update stdout ($in.stdout | str trim -c "\n")
2023-11-07 17:53:57 +01:00
2023-11-07 18:30:41 +01:00
let git_status = do { git status -s } | complete | get stdout | str trim -c "\n"
2023-11-07 17:53:57 +01:00
2023-11-07 18:32:03 +01:00
let git_changed = if $git_status == "" {
2023-11-07 23:41:30 +01:00
""
2023-11-07 17:53:57 +01:00
} else {
2023-11-07 23:41:30 +01:00
"*"
2023-11-07 17:53:57 +01:00
}
let git_branch_content = if $git_branch.exit_code == 0 {
2023-11-07 23:41:30 +01:00
[$git_color, " ", $git_branch.stdout, $git_changed, ""] | str join
} else {
""
}
# Current kube
let kube_color = ansi cyan_bold
2023-11-08 16:55:17 +01:00
let kube = if ("~/.kubes/current-cube" | path exists) {
2023-11-07 23:41:30 +01:00
let kube_name = open ~/.kubes/current-cube | path dirname | path basename
[$kube_color, " ", $kube_name, ""] | str join
2023-11-07 17:53:57 +01:00
} else {
2023-11-07 23:41:30 +01:00
""
2023-11-07 17:53:57 +01:00
}
2023-11-07 15:48:00 +01:00
[
2023-11-07 23:41:30 +01:00
$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
$git_branch_content
$kube
"\n"
$reset_ansi
$arrow_color
$second_line_arrow
2023-11-07 15:48:00 +01:00
] | 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 17:53:57 +01:00
"\e[B"
2023-11-07 15:48:00 +01:00
(ansi red_bold)
($env.LAST_EXIT_CODE)
" ↵ "
] | str join)
} else {([
2023-11-07 17:53:57 +01:00
"\e[B"
2023-11-07 15:48:00 +01:00
(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
]
2023-11-08 12:19:09 +01:00
# LS_COLORS so that ls mimics the colors of exa
$env.LS_COLORS = ([
# File types
"ex=1;32" # Executables
"di=1;34" # Directories
"ln=36" # Links
"or=31" # Orphan
# Media types
"*.pdf=32" # PDF files
# Images
"*.webp=35" # Webp image
"*.png=35" # PNG image
"*.jpg=35" # JPG image
# Music
"*.ogg=36" # OGG sound
"*.mp3=36" # MP3 sound
# Videos
"*.mp4=1;35" # MP4 video
"*.avi=1;35" # AVI video
"*.webm=1;35" # WebM video
# Bold yellow: source code
"*.c=1;33" # C source
"*.h=1;33" # C header
"*.cpp=1;33" # C++ source
"*.hpp=1;33" # C++ header
"*.inl=1;33" # C++ include
"*.cxx=1;33" # C++ include
"*.py=1;33" # Python
"*.js=1;33" # JavaScript
"*.ts=1;33" # TypeScript
"*.rs=1;33" # Rust
"*.elm=1;33" # Elm
2023-11-08 12:58:43 +01:00
"*.nu=1;33" # Nushell
2023-11-08 12:19:09 +01:00
# Build / doc files
"*Makefile=1;4;33" # Makefile
"*Dockerfile=1;4;33" # Dockerfile
"*.md=1;4;33" # Markdown
"*.toml=1;4;33" # Toml
] | str join ":")
2023-11-07 23:41:30 +01:00
# French by default
$env.LANG = fr_FR.UTF-8
# Gnome Keyring Daemon
$env.GNOME_KEYRING_DAEMON = '/run/user/1000/keyring'
2023-11-07 17:53:57 +01:00
# Text file editor
$env.EDITOR = nvim
# Backtrace for rust
$env.RUST_BACKTRACE = full
# Gclone env
2023-11-07 23:41:30 +01:00
$env.GCLONE_PATH = '/home/thomas/git'
2023-11-17 16:25:05 +01:00
$env.GCLONE_FORCE_SSH = true
2023-11-07 17:53:57 +01:00
# Python virtual env
$env.VIRTUAL_ENV = '/home/thomas/.venv'
2023-11-07 14:26:22 +01:00
# 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')
2023-11-07 17:53:57 +01:00
$env.PATH = ($env.PATH
| split row (char esep)
2023-11-13 11:54:39 +01:00
| prepend '/home/thomas/.config/polymny/bin'
2023-11-07 17:53:57 +01:00
| prepend '/home/thomas/.config/dotfiles/bin'
| prepend '/home/thomas/.config/dotfiles/bin-extra'
| prepend '/home/thomas/.cargo/bin'
| prepend '/home/thomas/.npmbin/bin'
| prepend '/home/thomas/.venv/bin'
)