Skip to content

Instantly share code, notes, and snippets.

@cptpiepmatz
Last active April 2, 2024 12:26
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
# 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
}
})
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