Skip to content

Instantly share code, notes, and snippets.

@cptpiepmatz
Last active May 20, 2025 20:55
Show Gist options
  • Save cptpiepmatz/0a05fbc6b9c8ce4711a56a34d18a7d34 to your computer and use it in GitHub Desktop.
Save cptpiepmatz/0a05fbc6b9c8ce4711a56a34d18a7d34 to your computer and use it in GitHub Desktop.
Nushell + Starship Config
$env.config.buffer_editor = "micro"
# Aliases
alias clip = clip.exe
# Starship
source ~/.cache/starship/init.nu
source ~/.cache/carapace/init.nu
# Custom Modules
# source ~/.nu/python.nu
source ~/.nu/azul-java.nu
source ~/.nu/nu_scripts/modules/formats/from-env.nu
# Plugin Config
$env.config.plugins.highlight.theme = "Monokai Extended Origin"
# set NU_OVERLAYS with overlay list, useful for starship prompt
$env.config.hooks.pre_prompt = ($env.config.hooks.pre_prompt | append {||
let nu_overlays = (overlay list | slice 1.. | str join ", ")
if ($nu_overlays | str length | into bool) {
$env.NU_OVERLAYS = $nu_overlays
} else {
$env.NU_OVERLAYS = null
}
})
let secrets = open ~/secrets.nuon | transpose dir env
$env.known_secrets = []
$env.config.hooks.pre_prompt = ($env.config.hooks.pre_prompt | append {||
for secret in $env.known_secrets {
hide-env $secret
}
$env.known_secrets = []
$env.NU_KNOWN_SECRETS = null
for entry in $secrets {
if (pwd | path expand | str starts-with $entry.dir) {
load-env $entry.env
$env.known_secrets ++= ($entry.env | columns)
}
}
if ($env.known_secrets | is-not-empty) {
$env.NU_KNOWN_SECRETS = $env.known_secrets | each {"" + $in} | str join "\n"
}
})
$env.config.hooks.pre_prompt = ($env.config.hooks.pre_prompt | append {||
$env.NU_IS_DEV = null
if ('nushell\target' in $nu.current-exe or 'nushell/target' in $nu.current-exe) {
$env.NU_IS_DEV = true
}
})
$env.VIRTUAL_ENV_DISABLE_PROMPT = true
$env.ENV_CONVERSIONS = $env.ENV_CONVERSIONS | merge {
"SOME_ENV": {
from_string: { |s| print "running from_string"; $s }
to_string: { |v| print "running to_string"; $v }
}
}
def --env cdr [] {
cd (^git rev-parse --show-toplevel)
}
const ZULU_HOME = 'C:\Program Files\Zulu'
def zulu_bin [version: int] {
return $'($ZULU_HOME)\zulu-($version)\bin'
}
module java6 {
export-env {
$env.PATH = ($env.PATH | append (zulu_bin 6))
}
}
module java7 {
export-env {
$env.PATH = ($env.PATH | append (zulu_bin 7))
}
}
module java8 {
export-env {
$env.PATH = ($env.PATH | append (zulu_bin 8))
}
}
module java9 {
export-env {
$env.PATH = ($env.PATH | append (zulu_bin 9))
}
}
module java10 {
export-env {
$env.PATH = ($env.PATH | append (zulu_bin 10))
}
}
module java11 {
export-env {
$env.PATH = ($env.PATH | append (zulu_bin 11))
}
}
module java12 {
export-env {
$env.PATH = ($env.PATH | append (zulu_bin 12))
}
}
module java13 {
export-env {
$env.PATH = ($env.PATH | append (zulu_bin 13))
}
}
module java14 {
export-env {
$env.PATH = ($env.PATH | append (zulu_bin 14))
}
}
module java15 {
export-env {
$env.PATH = ($env.PATH | append (zulu_bin 15))
}
}
module java16 {
export-env {
$env.PATH = ($env.PATH | append (zulu_bin 16))
}
}
module java17 {
export-env {
$env.PATH = ($env.PATH | append (zulu_bin 17))
}
}
module java18 {
export-env {
$env.PATH = ($env.PATH | append (zulu_bin 18))
}
}
module java19 {
export-env {
$env.PATH = ($env.PATH | append (zulu_bin 19))
}
}
module java20 {
export-env {
$env.PATH = ($env.PATH | append (zulu_bin 20))
}
}
module java21 {
export-env {
$env.PATH = ($env.PATH | append (zulu_bin 21))
}
}
module java22 {
export-env {
$env.PATH = ($env.PATH | append (zulu_bin 22))
}
}
# Nushell Environment Config File
#
# version = "0.100.0"
# 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
# The default for this is $nu.default-config-dir/scripts
$env.NU_LIB_DIRS = [
($nu.default-config-dir | path join 'scripts') # add <nushell-config-dir>/scripts
($nu.data-dir | path join 'completions') # default home for nushell completions
]
# Directories to search for plugin binaries when calling register
# The default for this is $nu.default-config-dir/plugins
$env.NU_PLUGIN_DIRS = [
($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')
# An alternate way to add entries to $env.PATH is to use the custom command `path add`
# which is built into the nushell stdlib:
# use std "path add"
# $env.PATH = ($env.PATH | split row (char esep))
# path add /some/path
# path add ($env.CARGO_HOME | path join "bin")
# path add ($env.HOME | path join ".local" "bin")
# $env.PATH = ($env.PATH | uniq)
# To load from a custom file you can use:
# source ($nu.default-config-dir | path join 'custom.nu')
mkdir ~/.cache/starship
starship init nu | save -f ~/.cache/starship/init.nu
# This needs to be a string.
# Otherwise this does not work.
$env.PIP_REQUIRE_VIRTUALENV = "true"
$env.CARAPACE_BRIDGES = 'zsh,fish,bash,inshellisense' # optional
mkdir ~/.cache/carapace
carapace _carapace nushell | save --force ~/.cache/carapace/init.nu
def "from env" []: string -> record {
lines
| split column '#'
| get column1
| filter {($in | str length) > 0}
| parse "{key}={value}"
| update value {str trim -c '"'}
| transpose -r -d
}
module python {
def env_used_path [] {
$env | columns | where {str downcase | $in == "path"} | get 0
}
# add more as needed
def python_home [] {
match $nu.os-info.name {
"windows" => ($env.LOCALAPPDATA + '\Programs\Python')
}
}
def paths [version] {
let python_home = ((python_home) + (char psep) + 'Python' + ($version | to text))
let python_scripts = ($python_home + (char psep) + 'Scripts')
[$python_home, $python_scripts]
}
export module python3.8 {
export-env {
let env_used_path = env_used_path
$env | get $env_used_path | prepend (paths 38) | {$env_used_path: $in} | load-env
}
}
export module python3.11 {
export-env {
let env_used_path = env_used_path
$env | get $env_used_path | prepend (paths 311) | {$env_used_path: $in} | load-env
}
}
}
use python python3.8
use python python3.11
#!/usr/bin/env nu
# execute a file on a remote machine
def main [
address: string,
local: string,
remote: string
] {
scp $local ($address + ":" + $remote)
print $"\n(ansi green)Executing ($remote)(ansi reset)"
ssh $address $remote
}
# Execute a binary on a remote system
def rexec [
address: string, # Address passed to scp and ssh
local: string, # Local file path
remote: string # Remote file path
] {
main $address $local $remote
}
# Get editor completions based on the config schema
"$schema" = 'https://starship.rs/config-schema.json'
# Inserts a blank line between shell prompts
add_newline = true
format = """\
${env_var.NU_IS_DEV}\
$all\
${env_var.NU_KNOWN_SECRETS}\
$time\
$line_break\
$status\
$os\
$container\
$netns\
$shell\
$character"""
[character]
format = '$indicator$symbol '
# Disable the package module, hiding it from the prompt completely
[package]
disabled = true
[status]
disabled = false
format = '[$status]($style) '
[git_status]
disabled = true
[shell]
disabled = false
[env_var.NU_IS_DEV]
format = '🛠️ '
[env_var.NU_OVERLAYS]
symbol = '📌 '
format = 'with [$symbol($env_value )]($style)'
style = 'red'
[env_var.NU_KNOWN_SECRETS]
format = "vaulting [$symbol(\n$env_value )]($style)"
style = 'bold fg:161'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment