repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

nushell/env.nu

Raw
# GLOBAL VARIABLES

#TODO move to config.nu

$env.WIN32 = ( $nu.os-info.name =~ "windows" )
$env.TERMUX = ( $nu.os-info.name =~ "android" )

$env.WORKSPACE = if $env.WIN32 { "~/Workspaces" } else { "~/Workspace" | path expand }
$env.DOTFILES  = ( $env.WORKSPACE | path join 'dotfiles' | path expand)
$env.NOTES = ("~/Notes" | path expand)
$env.TOOLS = ("~/Tools" | path expand)
$env.CARGO_HOME = ( "~/.cargo" | path expand )
$env.GO_HOME = ( "~/.go" | path expand )
$env.DOT_LOCAL = ( "~/.local" | path expand )
$env.DIFFTOOL = "zeditor --wait --diff"
$env.OPENCODE_HOME = ( "~/.opencode" | path expand)

if (not $env.WIN32) {
	# make sure to start ssh-agent user service: userctl enable --now ssh-agent
	$env.SSH_AUTH_SOCK = $"($env.XDG_RUNTIME_DIR)/ssh-agent.socket"
}

$env.PI_SKIP_VERSION_CHECK = true
$env.PI_TELEMETRY = true
# this seems to be ignored! duplicated in settings for now...
$env.PI_CODING_AGENT_SESSION_DIR = "~/.local/state/pi/sessions" | path expand
$env.PI_CACHE_RETENTION = "long"

if (which sccache | is-not-empty) { $env.RUSTC_WRAPPER = "sccache" }

if $env.WIN32 {
	$env.Path = (
  $env.Path
  | split row (char esep)
  | append ($env.CARGO_HOME | path join bin)
  | append ($env.GO_HOME | path join bin)
  | append ($env.TOOLS | path join bin)
  | append ($env.OPENCODE_HOME | path join bin)
  | uniq # filter so the paths are unique
)
} else {
	$env.PATH = (
  $env.PATH
  | split row (char esep)
  | append ($env.CARGO_HOME | path join bin)
  | append ($env.GO_HOME | path join bin)
  | append ($env.TOOLS | path join bin)
  | append ($env.OPENCODE_HOME | path join bin)
  | append ($env.DOT_LOCAL | path join bin)
  | uniq # filter so the paths are unique
)
}

if (which nvim | is-not-empty) {
	$env.EDITOR = 'nvim'
	$env.GIT_EDITOR = 'nvim'
}

if (which neovide | is-not-empty) {
	$env.VISUAL = 'neovide'
}

$env.LS_COLORS = 'rs=0:di=1;34:ln=1;35:ex=1;32:bd=1;33;40:cd=1;33;40:pi=33:so=35:do=35:or=1;31:mi=1;37;41:su=37;41:sg=30;43:tw=30;41:ow=37;41:st=37;44:*.tar=1;31:*.tgz=1;31:*.zip=1;31:*.gz=1;31:*.xz=1;31:*.7z=1;31:*.rar=1;31:*.jpg=1;35:*.png=1;35:*.gif=1;35:*.bmp=1;35:*.mp4=1;33:*.mp3=1;33:*.flac=1;33:*.pdf=1;33:*.doc=1;33:*.docx=1;33:*.txt=0:*.md=0:*.c=1;34:*.cpp=1;34:*.h=1;34:*.java=1;34:*.py=1;34:*.sh=1;34:'

# 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) }
    to_string: { |v| $v | str join (char esep) }
  }
  "Path": {
    from_string: { |s| $s | split row (char esep) }
    to_string: { |v| $v | str join (char esep) }
  }
}

$env.NU_LIB_DIRS = [
	($nu.default-config-dir | path join 'modules')
]

# generate aliases here and now, so that we can apply conditions.
# later, in config.nu, the evaluated aliases will be sourced
source ($nu.default-config-dir | path join 'gen-aliases.nu')
source ($nu.default-config-dir | path join 'gen-secrets.nu')

# TODO move to vendor dirs

# generate zoxide hooks for sourcing later on
let zoxide_config_path = $nu.default-config-dir | path join 'zoxide.nu'
if not (which zoxide | is-empty) {
	zoxide init nushell | save --force $zoxide_config_path
} else {
	'' | save -f $zoxide_config_path
}

# Carapace bridges available on this system: bash.
# fish/zsh/inshellisense executables are not installed, so those bridges add no completions.
$env.CARAPACE_BRIDGES = 'bash'
$env.CARAPACE_LENIENT = 1

if not (which mise | is-empty) {
	mkdir ($nu.vendor-autoload-dirs | last)
	^mise activate nu | save --force ($nu.vendor-autoload-dirs | last | path join 'mise.nu')
}

if not (which niri | is-empty) {
	mkdir ($nu.vendor-autoload-dirs | last)
	^niri completions nushell | save --force ($nu.vendor-autoload-dirs | last | path join 'niri.nu')
}