From 728e5e2f952e24768ac88ab047666df861503bb5 Mon Sep 17 00:00:00 2001 From: Riz Ashraf Date: Tue, 7 Apr 2026 00:53:34 +0100 Subject: [PATCH] Templatize Nushell configs for cross-platform use --- .../nushell/{config.nu => config.nu.tmpl} | 25 +++++++--- AppData/Roaming/nushell/env.nu | 35 ------------- AppData/Roaming/nushell/env.nu.tmpl | 50 +++++++++++++++++++ 3 files changed, 67 insertions(+), 43 deletions(-) rename AppData/Roaming/nushell/{config.nu => config.nu.tmpl} (70%) delete mode 100644 AppData/Roaming/nushell/env.nu create mode 100644 AppData/Roaming/nushell/env.nu.tmpl diff --git a/AppData/Roaming/nushell/config.nu b/AppData/Roaming/nushell/config.nu.tmpl similarity index 70% rename from AppData/Roaming/nushell/config.nu rename to AppData/Roaming/nushell/config.nu.tmpl index 3bec41a..65c3659 100644 --- a/AppData/Roaming/nushell/config.nu +++ b/AppData/Roaming/nushell/config.nu.tmpl @@ -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 +} diff --git a/AppData/Roaming/nushell/env.nu b/AppData/Roaming/nushell/env.nu deleted file mode 100644 index f17052b..0000000 --- a/AppData/Roaming/nushell/env.nu +++ /dev/null @@ -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 diff --git a/AppData/Roaming/nushell/env.nu.tmpl b/AppData/Roaming/nushell/env.nu.tmpl new file mode 100644 index 0000000..1713e9b --- /dev/null +++ b/AppData/Roaming/nushell/env.nu.tmpl @@ -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"