Skip to content

Instantly share code, notes, and snippets.

@cptpiepmatz
Last active August 4, 2024 19:53
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
# Append to config.nu
# Config Updates
$env.config.buffer_editor = "micro"
# Aliases
alias clip = clip.exe
# Starship
source ~/.cache/starship/init.nu
# Custom Commands
source ~/.nu/rexec.nu
source ~/.nu/from-env.nu
# Custom Modules
source ~/.nu/python.nu
source ~/.nu/azul-java.nu
# External Modules
use ~/.nu/nu_scripts/modules/fnm/fnm.nu
# External Completions
use ~/.nu/nu_scripts/custom-completions/cargo/cargo-completions.nu *
use ~/.nu/nu_scripts/custom-completions/gh/gh-completions.nu *
use ~/.nu/nu_scripts/custom-completions/git/git-completions.nu *
use ~/.nu/nu_scripts/custom-completions/make/make-completions.nu *
use ~/.nu/nu_scripts/custom-completions/npm/npm-completions.nu *
use ~/.nu/nu_scripts/custom-completions/pnpm/pnpm-completions.nu *
use ~/.nu/nu_scripts/custom-completions/rustup/rustup-completions.nu *
use ~/.nu/nu_scripts/custom-completions/typst/typst-completions.nu *
use ~/.nu/nu_scripts/custom-completions/vscode/vscode-completions.nu *
use ~/.nu/nu_scripts/custom-completions/winget/winget-completions.nu *
use ~/.nu/nu_scripts/custom-completions/yarn/yarn-v4-completions.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 | range 1.. | str join ", ")
if ($nu_overlays | str length | into bool) {
$env.NU_OVERLAYS = $nu_overlays
} else {
$env.NU_OVERLAYS = null
}
})
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))
}
}
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"
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
[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_OVERLAYS]
symbol = '📌 '
format = 'with [$symbol($env_value )]($style)'
style = 'red'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment