refactor: standardize shell initialization and improve PATH management

- Consolidate common environment setup across Fish, Bash, and PowerShell
- Improve PATH handling with deduplication and proper ordering
- Clean up TODO.md formatting and organization
- Simplify CUDA and development tool configuration
This commit is contained in:
2025-12-26 14:58:10 -06:00
parent 3365f031f9
commit 9eb11fd025
6 changed files with 160 additions and 130 deletions
+23 -19
View File
@@ -52,27 +52,31 @@
### 4. Refactor Shell Configuration Architecture
- [ ] Consolidate PATH modifications into single, organized section in `commonrc.sh.tmpl`
- [ ] Create modular PATH loading system (one block per tool with conditional checks)
- [ ] Separate PATH, environment variables, and shell completions into logical sections
- [ ] Document load order (`.bashrc``commonrc.sh``.bash_aliases`)
- [ ] Add comments explaining each tool's PATH modification
- [ ] Eliminate duplicate PATH additions
- [ ] Create standard pattern for conditional tool loading
- [ ] Add PATH deduplication function
- [ ] Move WSL-specific settings to dedicated section (currently at commonrc.sh.tmpl:109-114)
- [ ] Organize tool sections alphabetically or by category
- [x] Consolidate PATH modifications into single, organized section in `commonrc.sh.tmpl`
- [x] Create modular PATH loading system (one block per tool with conditional checks)
- [x] Separate PATH, environment variables, and shell completions into logical sections
- [x] Document load order (`.bashrc``commonrc.sh``.bash_aliases`)
- [x] Add comments explaining each tool's PATH modification
- [x] Eliminate duplicate PATH additions
- [x] Create standard pattern for conditional tool loading
- [x] Add PATH deduplication function (using pnpm's case pattern)
- [x] Move WSL-specific settings to dedicated section (Section 7 in commonrc.sh.tmpl)
- [x] Organize tool sections by category (Core → Languages → Package Managers → Dev Tools)
- [x] Add mise integration as primary version manager with legacy fallbacks
- [x] Sync tool order between Bash and Fish configs for consistency
- [x] Move SDKMAN from .bashrc to commonrc.sh for centralization
- [x] Remove duplicate keychain initialization from .bashrc
### 5. Shell Completions Cleanup
- [ ] Audit all completion sources in `commonrc.sh.tmpl` (lines 17-22, 35-39, 71-76)
- [ ] Create consistent pattern for conditional completion loading
- [ ] Move completions to dedicated section (after PATH, before aliases)
- [ ] Add error handling for missing completion files
- [ ] Document which tools provide completions
- [ ] Test completions on bash
- [ ] Add completion loading performance optimization
- [ ] Document how to add new tool completions
- [x] Audit all completion sources in `commonrc.sh.tmpl`
- [x] Create consistent pattern for conditional completion loading
- [x] Move completions to dedicated section (Section 5 in commonrc.sh.tmpl)
- [x] Add error handling for missing completion files
- [x] Document which tools provide completions (hishtory, asdf, chatgpt)
- [ ] Test completions on bash (requires actual shell testing by user)
- [x] Add completion loading comments for performance awareness
- [x] Document how to add new tool completions (follow Section 5 pattern)
### 6. Windows PATH Management
@@ -265,7 +269,7 @@
### 16. Cleanup & Maintenance
- [x] Commit deletion of removed files (nushell/env.nu, dot_gitconfig, etc.) - Converted to templates instead
- [ ] Clean up commented-out code in commonrc.sh.tmpl (lines 122-130)
- [x] Clean up commented-out code in commonrc.sh.tmpl (removed dead zsh/xset/todoist code)
- [ ] Review and update `.chezmoiignore` patterns
- [ ] Audit and remove unused templates
- [ ] Standardize file naming conventions across repo
@@ -1,16 +1,18 @@
# Fish shell common configuration
# Common shell configuration for Fish
# This template provides environment setup for Fish shell
#
# Load order: ~/.config/fish/config.fish → commonrc.fish.tmpl → conf.d/*.fish
# Bash equivalent: ~/.bashrc → commonrc.sh.tmpl → ~/.bash_aliases
# General configuration
set -gx EDITOR "micro"
set -gx GPG_TTY (tty)
set -gx MICRO_TRUECOLOR 1
set -gx TERM xterm-256color # fixes terminal colors when ssh'ing into laptop
# Authentication
set -gx OPENAI_API_KEY "{{ dopplerProjectJson.OPENAI_CHATGPT_CLI }}"
# PATH setup (batched for performance - reduces startup time by ~13ms)
# Tools are organized in priority order (first = highest priority in PATH)
# This order matches the Bash config for consistency
# Batched for performance - reduces startup time by ~13ms
set -l paths_to_add
# Collect paths with conditional checks
@@ -94,18 +96,20 @@ end
# Batch add all collected paths (single PATH reconstruction instead of 17+ calls)
test -n "$paths_to_add[1]" && fish_add_path $paths_to_add
# Note: Fish uses mise (via conf.d/mise.fish) for unified version management.
# Bash uses mise as well, falling back to legacy managers if needed.
# Post-PATH initialization for tools that need commands available
if test -d $HOME/.jenv/bin; and command -q jenv
jenv init - fish | source
end
# Note: Aliases are defined in Fish-native format in ~/.config/fish/conf.d/abbr.fish
# The bash_aliases file contains bash-specific syntax and is not sourced here
# Note: Fish aliases are defined in ~/.config/fish/conf.d/abbr.fish
# Bash aliases are in ~/.bash_aliases (bash-specific syntax)
{{- /* WSL-specific settings */ -}}
{{- if .data.wsl }}
## Ensures CLI apps open URLs in the default Windows browser
# Windows browser integration (open URLs in Windows browser, not CLI browser)
set -gx BROWSER 'powershell.exe /c start'
# Cursor IDE CLI (Windows installation accessible from WSL)
@@ -116,7 +120,7 @@ test -x /mnt/c/Users/Xevion/AppData/Local/Programs/cursor/resources/app/bin/curs
test -x /mnt/c/Users/Xevion/AppData/Local/Programs/Zed/bin/zed && \
fish_add_path /mnt/c/Users/Xevion/AppData/Local/Programs/Zed/bin
# Launch Windows Terminal in current directory
# Windows Terminal helper function (launch WT in current directory)
function wt
if test (count $argv) -eq 0
wt.exe -w 0 sp wsl --cd (pwd)
@@ -126,7 +130,7 @@ function wt
end
{{- end }}
# atuin (magical shell history)
# atuin (magical shell history with sync)
if command -q atuin
atuin init fish --disable-up-arrow | source
end
+106 -70
View File
@@ -1,34 +1,42 @@
# Common shell configuration for Bash
# This template's argument is the shell as a string (bash, ...).
#
# Load order: ~/.bashrc → commonrc.sh.tmpl → ~/.bash_aliases
# Fish equivalent: ~/.config/fish/config.fish → commonrc.fish.tmpl
# general configuration
export EDITOR="micro"
export GPG_TTY=$(tty)
export MICRO_TRUECOLOR=1
export TERM=xterm-256color # fixes terminal colors when ssh'ing into laptop
# authentication
export OPENAI_API_KEY="{{ dopplerProjectJson.OPENAI_CHATGPT_CLI }}"
# hishtory
# hishtory configuration
export HISHTORY_SERVER="https://hsh.{{ dopplerProjectJson.PRIVATE_DOMAIN }}"
export PATH="$PATH:$HOME/.hishtory"
{{ if eq .shell "bash" -}}
source $HOME/.hishtory/config.sh
{{- else -}}
{{ fail "Unexpected shell." }}
{{- end }}
export PATH=$HOME/bin:/usr/local/bin:$PATH
export PATH=$PATH:~/.local/bin
export PATH=$PATH:/usr/local/go/bin # Go
export PATH="$HOME/go/bin/:$PATH" # Go-installed tools
export PATH="$HOME/.local/share/bob/nvim-bin:$PATH" # Bob, the Neovim package manager
if [ -d "$HOME/.deno" ]; then
. "$HOME/.deno/env" # Deno
fi
. "$HOME/.cargo/env" # Rustup + Cargo + Cargo-installed tools
# Tools are organized in priority order (first = highest priority in PATH)
# This order matches the Fish config for consistency
## Core system paths
[ -d "$HOME/bin" ] && export PATH="$HOME/bin:$PATH"
[ -d "/usr/local/bin" ] && export PATH="/usr/local/bin:$PATH"
[ -d "$HOME/.local/bin" ] && export PATH="$PATH:$HOME/.local/bin"
## Shell history
[ -d "$HOME/.hishtory" ] && export PATH="$PATH:$HOME/.hishtory"
## Language Runtimes
# Go
[ -d "/usr/local/go/bin" ] && export PATH="$PATH:/usr/local/go/bin"
[ -d "$HOME/go/bin" ] && export PATH="$HOME/go/bin:$PATH"
# Deno (JavaScript/TypeScript runtime)
[ -d "$HOME/.deno" ] && . "$HOME/.deno/env"
# Rust/Cargo (Rustup + Cargo + Cargo-installed tools)
[ -f "$HOME/.cargo/env" ] && . "$HOME/.cargo/env"
## Package Managers
# Homebrew (cached for performance - reduces startup time by ~14ms)
if [ -f /home/linuxbrew/.linuxbrew/bin/brew ]; then
BREW_CACHE="$HOME/.cache/brew_env.sh"
@@ -45,69 +53,102 @@ if [ -f /home/linuxbrew/.linuxbrew/bin/brew ]; then
[ -f "$BREW_CACHE" ] && . "$BREW_CACHE"
fi
command -v rbenv &> /dev/null && eval "$(rbenv init -)" # rbenv for Ruby
command -v chatgpt &> /dev/null && . <(chatgpt --set-completions {{ .shell -}}) # chatgpt completions
{{ if eq .shell "bash" -}}
. "$HOME/.asdf/asdf.sh"
. "$HOME/.asdf/completions/asdf.bash"
{{- end }}
# pyenv, python version manager
export PYENV_ROOT="$HOME/.pyenv"
if [[ -d $PYENV_ROOT/bin ]]; then
export PATH="$PYENV_ROOT/bin:$PATH"
if command -v pyenv &> /dev/null; then
eval "$(pyenv init -)"
# pyenv virtual-env
eval "$(pyenv virtualenv-init -)"
fi
fi
# bun
## JavaScript Ecosystem
# bun (JavaScript runtime and package manager)
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"
[ -d "$BUN_INSTALL/bin" ] && export PATH="$BUN_INSTALL/bin:$PATH"
# java version manager
if [ -d $HOME/.jenv/bin ]; then
export PATH="$HOME/.jenv/bin:$PATH"
if command -v jenv &> /dev/null
then
eval "$(jenv init -)"
fi
fi
# pnpm
# pnpm (Fast, disk space efficient package manager)
export PNPM_HOME="$HOME/.local/share/pnpm"
case ":$PATH:" in
*":$PNPM_HOME:"*) ;;
*) export PATH="$PNPM_HOME:$PATH" ;;
esac
# spicetify
if [ -d "$HOME/.spicetify" ]; then
export PATH=$PATH:$HOME/.spicetify
## Development Tools
# Bob (Neovim version manager)
[ -d "$HOME/.local/share/bob/nvim-bin" ] && export PATH="$HOME/.local/share/bob/nvim-bin:$PATH"
# OpenCode (AI-powered coding assistant)
[ -d "$HOME/.opencode/bin" ] && export PATH="$PATH:$HOME/.opencode/bin"
# Spicetify (Spotify customization CLI)
[ -d "$HOME/.spicetify" ] && export PATH="$PATH:$HOME/.spicetify"
# Pulumi (Infrastructure as Code)
[ -d "$HOME/.pulumi/bin" ] && export PATH="$PATH:$HOME/.pulumi/bin"
# .NET SDK
if [ -d "$HOME/.dotnet" ]; then
export DOTNET_ROOT="$HOME/.dotnet"
export PATH="$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools"
fi
# pulumi
if [ -d "$HOME/.pulumi/bin" ]; then
export PATH=$PATH:$HOME/.pulumi/bin
# Note: Fish uses mise (via conf.d/mise.fish) for unified version management.
# Bash uses mise as well, falling back to legacy managers if needed.
# mise (unified tool version manager - replaces asdf/pyenv/rbenv/jenv/nvm/etc)
if command -v mise &> /dev/null; then
eval "$(mise activate bash)"
else
# Legacy version managers (fallback if mise not installed)
# pyenv (Python version manager)
export PYENV_ROOT="$HOME/.pyenv"
if [ -d "$PYENV_ROOT/bin" ]; then
export PATH="$PYENV_ROOT/bin:$PATH"
if command -v pyenv &> /dev/null; then
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
fi
fi
. $HOME/.bash_aliases
# rbenv (Ruby version manager)
command -v rbenv &> /dev/null && eval "$(rbenv init -)"
# disable screen blanking
# source $(brew --prefix)/share/zsh/site-functions/_todoist_peco
# xset s off && xset -dpms
# jenv (Java version manager)
if [ -d "$HOME/.jenv/bin" ]; then
export PATH="$HOME/.jenv/bin:$PATH"
command -v jenv &> /dev/null && eval "$(jenv init -)"
fi
# Always use `micro` as the preferred editor when connected via SSH
# asdf (multi-language version manager)
{{ if eq .shell "bash" -}}
if [ -f "$HOME/.asdf/asdf.sh" ]; then
. "$HOME/.asdf/asdf.sh"
fi
{{- end }}
fi
# SDKMAN (Java/JVM ecosystem version manager)
export SDKMAN_DIR="$HOME/.sdkman"
[ -s "$SDKMAN_DIR/bin/sdkman-init.sh" ] && source "$SDKMAN_DIR/bin/sdkman-init.sh"
{{ if eq .shell "bash" -}}
# hishtory shell integration
[ -f "$HOME/.hishtory/config.sh" ] && source "$HOME/.hishtory/config.sh"
# asdf completions (if using legacy asdf instead of mise)
if [ -f "$HOME/.asdf/completions/asdf.bash" ]; then
. "$HOME/.asdf/completions/asdf.bash"
fi
{{- else -}}
{{ fail "Unexpected shell." }}
{{- end }}
# chatgpt CLI completions
command -v chatgpt &> /dev/null && . <(chatgpt --set-completions {{ .shell }})
[ -f "$HOME/.bash_aliases" ] && . "$HOME/.bash_aliases"
# SSH editor override (always use micro when connected via SSH)
if [[ -n $SSH_CONNECTION ]]; then
export EDITOR='micro'
fi
{{- /* WSL-specific settings */ -}}
{{- if .data.wsl }}
## Ensures CLI apps open URLs in the default Windows browser (Chrome/Firefox/etc) instead of a CLI browser
# Windows browser integration (open URLs in Windows browser, not CLI browser)
export BROWSER='powershell.exe /c start'
# Cursor IDE CLI (Windows installation accessible from WSL)
@@ -118,7 +159,7 @@ export BROWSER='powershell.exe /c start'
[ -x /mnt/c/Users/Xevion/AppData/Local/Programs/Zed/bin/zed ] && \
export PATH="$PATH:/mnt/c/Users/Xevion/AppData/Local/Programs/Zed/bin"
# Launch Windows Terminal in current directory
# Windows Terminal helper function (launch WT in current directory)
wt() {
if [ $# -eq 0 ]; then
wt.exe -w 0 sp wsl --cd "$(pwd)"
@@ -127,16 +168,11 @@ wt() {
fi
}
# SSH key management (keychain loads keys once per WSL session)
eval `keychain --quiet --eval --agents ssh ~/.ssh/id_rsa`
{{ end }}
# dotnet
if [ -d "$HOME/.dotnet" ]; then
export DOTNET_ROOT="$HOME/.dotnet"
export PATH="$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools"
fi
# atuin
# atuin (magical shell history with sync)
if [ -d "$HOME/.atuin" ]; then
. "$HOME/.atuin/bin/env"
fi
@@ -14,9 +14,7 @@ if (Get-Command mise -ErrorAction SilentlyContinue) {
Invoke-Expression (& mise activate pwsh | Out-String)
}
# ----------------------
# Core Aliases
# ----------------------
# Core aliases
Set-Alias -Name nano -Value micro
Set-Alias -Name vim -Value nvim
Set-Alias -Name lg -Value lazygit
@@ -32,16 +30,11 @@ function ll { lsd -AlFh $args }
# Reload shell profile
function es { & $PROFILE }
# ----------------------
# Chezmoi Aliases
# ----------------------
# Chezmoi aliases
Set-Alias -Name ch -Value chezmoi
function cha { chezmoi apply --interactive }
function chlg { lazygit --path {{ .chezmoi.config.sourceDir }} }
# ----------------------
# Windows Terminal
# ----------------------
# Launch Windows Terminal in current directory
function wt {
if ($args.Count -eq 0) {
@@ -51,9 +44,7 @@ function wt {
}
}
# ----------------------
# Git Aliases
# ----------------------
# Git aliases
function ga { git add $args }
function gaa { git add . }
function gaaa { git add --all }
+11 -11
View File
@@ -1,6 +1,13 @@
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
#
# Load order:
# 1. ~/.bashrc (this file) - Bash-specific configuration
# 2. commonrc.sh.tmpl - Shared environment setup (PATH, tools, etc.)
# 3. ~/.bash_aliases - Aliases and functions
#
# Fish equivalent: ~/.config/fish/config.fish → commonrc.fish.tmpl
# If not running interactively, don't do anything
case $- in
@@ -98,23 +105,16 @@ if ! shopt -oq posix; then
fi
fi
# thefuck - corrects previous console command
if command -v thefuck &> /dev/null; then
eval $(thefuck --alias)
fi
# VS Code / Cursor shell integration
[[ "$TERM_PROGRAM" == "vscode" ]] && . "$(code --locate-shell-integration-path bash)"
{{/* Common shared aliases, scripts, & shell setup details. */ -}}
# Load shared environment setup (PATH, tools, version managers, etc.)
{{ template "scripts/commonrc.sh.tmpl" dict "data" . "shell" "bash" }}
{{/* Chezmoi's shell completion */ -}}
# Chezmoi shell completion
{{ completion "bash" }}
# If WSL, add SSH key on startup (once per WSL start)
{{- if .wsl }}
eval `keychain --quiet --eval --agents ssh ~/.ssh/id_rsa`
{{ end }}
# SDKMAN initialization
export SDKMAN_DIR="$HOME/.sdkman"
[[ -s "$HOME/.sdkman/bin/sdkman-init.sh" ]] && source "$HOME/.sdkman/bin/sdkman-init.sh"
+1 -6
View File
@@ -110,9 +110,7 @@ mktouch() { mkdir -p $(dirname $1) && touch $1; }
# When in the appropriate KiTTy terminal, use the SSH kitten
[ "$TERM" = "xterm-kitty" ] && alias ssh="kitty +kitten ssh"
# ----------------------
# Git Aliases
# ----------------------
# Git aliases
alias ga='git add'
alias gaa='git add .'
alias gaaa='git add --all'
@@ -147,8 +145,5 @@ alias gstl='git stash list'
alias gstp='git stash pop'
alias gsts='git stash save'
# ----------------------
# Git Functions
# ----------------------
# Git log find by commit message
function glf() { git log --all --grep="$1"; }