Templatize Nushell configs for cross-platform use

This commit is contained in:
Riz Ashraf
2026-04-07 00:53:34 +01:00
parent c33ea4edac
commit 728e5e2f95
3 changed files with 67 additions and 43 deletions
@@ -1,5 +1,4 @@
# config.nu
# Nushell Configuration
# Nushell Configuration (Templated)
# Standard Library
use std
@@ -39,6 +38,9 @@ if (which eza | is-not-empty) {
if (which bat | is-not-empty) {
alias cat = bat -P
} else if (which batcat | is-not-empty) {
alias cat = batcat -P
alias bat = batcat
}
if (which rg | is-not-empty) {
@@ -47,7 +49,7 @@ if (which rg | is-not-empty) {
if (which fd | is-not-empty) {
alias find = fd
alias f = fd
alias ff = fd
}
if (which yazi | is-not-empty) {
@@ -55,19 +57,26 @@ if (which yazi | is-not-empty) {
}
# Source tool integrations generated in env.nu
source ~/.cache/nushell/zoxide.nu
source ~/.cache/nushell/starship.nu
source ($env.CACHE_DIR | path join "zoxide.nu")
source ($env.CACHE_DIR | path join "starship.nu")
# Java and JDK Utilities
use java-utils.nu *
# Visual Studio Utilities
{{ if eq .chezmoi.os "windows" -}}
# Visual Studio Utilities (Windows Only)
use vs-utils.nu *
{{- end }}
# Git completions
# completions
use completions/git-completions.nu *
{{ if eq .chezmoi.os "windows" -}}
use completions/scoop-completions.nu *
{{- end }}
use completions/pnpm-completions.nu *
use completions/uv-completions.nu *
jdk25home --quiet
# Set default JDK
if (which jdk25home | is-not-empty) {
jdk25home --quiet
}
-35
View File
@@ -1,35 +0,0 @@
# env.nu
# Nushell Environment Configuration
# Ensure cache directory exists
try { mkdir ~/.cache/nushell }
# Initialize Zoxide
if (which zoxide | is-not-empty) {
zoxide init nushell | save -f ~/.cache/nushell/zoxide.nu
} else {
"" | save -f ~/.cache/nushell/zoxide.nu
}
# Initialize Starship
if (which starship | is-not-empty) {
starship init nu | save -f ~/.cache/nushell/starship.nu
} else {
"" | save -f ~/.cache/nushell/starship.nu
}
# Set default editor and pager
$env.EDITOR = "nvim"
$env.VISUAL = "nvim"
$env.PAGER = "bat --paging=always"
# Modern PowerShell 7 wrapper (pw7) for Nushell
# This matches the behavior of the PowerShell pw7 function by sourcing the Gemini profile
def --env pw7 [cmd: string] {
let profile = "C:\\Users\\reazul.ashraf\\onedrive\\Documents\\PowerShell\\Gemini_Profile.ps1"
# Use -NonInteractive and Out-String to ensure clean string output for JSON parsing
^pwsh.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command $". '($profile)'; ($cmd) | Out-String"
}
# Useful env variables
$env.BAT_THEME = "TwoDark" # Common default, adjust if needed
+50
View File
@@ -0,0 +1,50 @@
# Nushell Environment Configuration (Templated)
{{ if eq .chezmoi.os "windows" -}}
$env.CACHE_DIR = ($env.HOME | path join "AppData" "Local" "nushell" "cache")
{{- else -}}
$env.CACHE_DIR = ($env.HOME | path join ".cache" "nushell")
{{- end }}
# Ensure cache directory exists
try { mkdir $env.CACHE_DIR }
# Initialize Zoxide
if (which zoxide | is-not-empty) {
zoxide init nushell | save -f ($env.CACHE_DIR | path join "zoxide.nu")
} else {
"" | save -f ($env.CACHE_DIR | path join "zoxide.nu")
}
# Initialize Starship
if (which starship | is-not-empty) {
starship init nu | save -f ($env.CACHE_DIR | path join "starship.nu")
} else {
"" | save -f ($env.CACHE_DIR | path join "starship.nu")
}
# Set default editor and pager
{{ if eq .chezmoi.os "windows" -}}
$env.EDITOR = "nvim.exe"
$env.VISUAL = "nvim.exe"
{{- else -}}
$env.EDITOR = "nvim"
$env.VISUAL = "nvim"
{{- end }}
{{- if (which bat | is-not-empty) }}
$env.PAGER = "bat --paging=always"
{{- else if (which batcat | is-not-empty) }}
$env.PAGER = "batcat --paging=always"
{{- end }}
{{ if eq .chezmoi.os "windows" -}}
# Modern PowerShell 7 wrapper (pw7) for Nushell (Windows Only)
def --env pw7 [cmd: string] {
let profile = "{{ joinPath .chezmoi.homeDir "onedrive" "Documents" "PowerShell" "Gemini_Profile.ps1" }}"
^pwsh.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command $". '($profile)'; ($cmd) | Out-String"
}
{{- end }}
# Useful env variables
$env.BAT_THEME = "TwoDark"