bashrc.tmpl

  1# ============================================================================
  2# Environment Variables
  3# ============================================================================
  4
  5# XDG Base Directories
  6export XDG_DATA_HOME="$HOME/.local/share"
  7export XDG_CONFIG_HOME="$HOME/.config"
  8export XDG_STATE_HOME="$HOME/.local/state"
  9export XDG_CACHE_HOME="$HOME/.cache"
 10export XDG_BIN_HOME="$HOME/.local/bin"
 11export XDG_BIN_DIR="$XDG_BIN_HOME"
 12
 13# Moving dotfiles around
 14export WINEPREFIX="$XDG_DATA_HOME/wine"
 15export WORKON_HOME="$XDG_DATA_HOME/virtualenvs"
 16export SQLITE_HISTORY="$XDG_CACHE_HOME/sqlite_history"
 17export BUNDLE_USER_CONFIG="$XDG_CONFIG_HOME/bundle"
 18export BUNDLE_USER_CACHE="$XDG_CACHE_HOME/bundle"
 19export BUNDLE_USER_PLUGIN="$XDG_DATA_HOME/bundle"
 20export NUGET_PACKAGES="$XDG_CACHE_HOME/NuGetPackages"
 21export DVDCSS_CACHE="$XDG_DATA_HOME/dvdcss"
 22export KDEHOME="$XDG_CONFIG_HOME/kde"
 23export GOPATH="$XDG_DATA_HOME/go"
 24export ZIM_HOME="$XDG_CONFIG_HOME/.zim"
 25export GHCUP_USE_XDG_DIRS="ishouldjustbeabletoexportthisnotsetit"
 26export NODE_PATH="$XDG_DATA_HOME/npm-packages/lib/node_modules"
 27export CARGO_HOME="$XDG_DATA_HOME/cargo"
 28export ASDF_DATA_DIR="$XDG_DATA_HOME/asdf"
 29
 30# pi coding agent
 31export PI_CODING_AGENT_DIR="$XDG_CONFIG_HOME/pi"
 32
 33# Android SDK
 34export ANDROID_HOME="$XDG_DATA_HOME/Android"
 35export ANDROID_SDK_ROOT="$ANDROID_HOME"
 36
 37# ============================================================================
 38# PATH Configuration
 39# ============================================================================
 40
 41# Prepend paths in reverse order (last becomes first in PATH)
 42path_prepend() {
 43    case ":$PATH:" in
 44        *":$1:"*) :;; # already in PATH
 45        *) PATH="$1${PATH:+:$PATH}" ;;
 46    esac
 47}
 48
 49# XDG_BIN_HOME takes highest priority
 50path_prepend "$XDG_BIN_HOME"
 51path_prepend "$XDG_CACHE_HOME/.bun/bin"
 52path_prepend "$HOME/.radicle/bin"
 53path_prepend "$XDG_DATA_HOME/cargo/bin"
 54path_prepend "$GOPATH/bin"
 55path_prepend "$XDG_CONFIG_HOME/emacs/bin"
 56path_prepend "/usr/local/go/bin"
 57path_prepend "/usr/lib/kf5"
 58path_prepend "/usr/lib/kf6"
 59
 60# Android SDK paths
 61path_prepend "$ANDROID_HOME/emulator"
 62path_prepend "$ANDROID_HOME/platform-tools"
 63path_prepend "$ANDROID_HOME/cmdline-tools/latest/bin"
 64
 65# Guix
 66export GUIX_LOCPATH="$HOME/.guix-profile/lib/locale"
 67export GUIX_PROFILE="$HOME/.guix-profile"
 68path_prepend "$GUIX_PROFILE/bin"
 69
 70# ============================================================================
 71# Preferences and Tools
 72# ============================================================================
 73
 74export BAT_THEME="ansi"
 75export DFT_BACKGROUND="light"
 76{{ if eq .chezmoi.hostname "sidhe" }}
 77export EDITOR="zed --wait"
 78{{ else }}
 79export EDITOR="zeditor --wait"
 80{{ end }}
 81export VISUAL="$EDITOR"
 82export MANPAGER="nvim +Man!"
 83export COLUMNS=80
 84export MANWIDTH=80
 85export RIPGREP_CONFIG_PATH="$HOME/.config/ripgreprc"
 86export RANGER_LOAD_DEFAULT_RC=false
 87
 88# Disable Python keyring
 89export PYTHON_KEYRING_BACKEND="keyring.backends.null.Keyring"
 90
 91# mise
 92if command -v mise &> /dev/null; then
 93    eval "$(mise activate bash)"
 94fi
 95
 96# secrets (fnox)
 97if [[ -f "$XDG_CONFIG_HOME/fnox/age.txt" ]]; then
 98    export FNOX_AGE_KEY=$(grep "AGE-SECRET-KEY" "$XDG_CONFIG_HOME/fnox/age.txt")
 99    if command -v fnox &> /dev/null; then
100{{ if eq .chezmoi.username "exedev" }}
101        # Load secrets immediately for non-interactive shells (e.g., agents)
102        eval "$(mise exec fnox@latest -- fnox hook-env -s bash 2>/dev/null || true)"
103{{ end }}
104        eval "$(mise exec fnox@latest -- fnox activate bash 2>/dev/null || true)"
105    fi
106fi
107
108# ============================================================================
109# History Configuration
110# ============================================================================
111
112# Don't put duplicate lines or lines starting with space in the history
113HISTCONTROL=ignoreboth
114
115# Append to the history file, don't overwrite it
116shopt -s histappend
117
118# History size
119HISTSIZE=10000
120HISTFILESIZE=20000
121
122# Save history to XDG location
123export HISTFILE="$XDG_STATE_HOME/bash/history"
124mkdir -p "$(dirname "$HISTFILE")"
125
126# ============================================================================
127# Shell Options
128# ============================================================================
129
130# Check window size after each command and update LINES/COLUMNS
131shopt -s checkwinsize
132
133# Enable ** globstar (if available)
134shopt -s globstar 2>/dev/null
135
136# Enable programmable completion
137if ! shopt -oq posix; then
138    if [[ -f /usr/share/bash-completion/bash_completion ]]; then
139        source /usr/share/bash-completion/bash_completion
140    elif [[ -f /etc/bash_completion ]]; then
141        source /etc/bash_completion
142    fi
143fi
144
145# ============================================================================
146# Aliases
147# ============================================================================
148
149{{ if ne .chezmoi.hostname "sidhe" }}
150alias zed="zeditor"
151{{ end }}
152
153alias wget="wget --hsts-file=\"$XDG_DATA_HOME/wget-hsts\""
154alias svn="svn --config-dir $XDG_CONFIG_HOME/subversion"
155alias ts="tailscale"
156alias datetime="date +%Y-%m-%d_%H%M%S_%Z"
157alias clip="xclip -selection clipboard"
158alias send="rsync -amzzP"
159alias bat="bat -n --tabs 2"
160alias erase="shred -vzfun 32"
161alias dl="yt-dlp --write-sub --write-auto-sub --sub-lang en --sub-format srt/best --convert-subs srt --embed-subs -o '%(upload_date)s %(title)s.%(ext)s'"
162alias us="unsilence -t 15 -as 1.25"
163alias sxiv="sxiv -p"
164alias c="chezmoi"
165alias t="tuios"
166alias ls="lsd"
167alias soft="ssh git.secluded.site"
168alias g="git"
169
170# Modern replacements
171alias ll='ls -la'
172alias la='ls -a'
173
174# ============================================================================
175# Functions
176# ============================================================================
177
178# cheat.sh integration
179cht() {
180    if [[ $# -eq 0 ]]; then
181        echo "Usage: cht <topic> or cht <language>/<query>"
182        return 1
183    fi
184    curl -s "cheat.sh/$*"
185}
186
187# ============================================================================
188# Tool Integrations
189# ============================================================================
190
191# Starship prompt
192if command -v starship &> /dev/null; then
193    eval "$(starship init bash)"
194fi
195
196# Atuin history
197if command -v atuin &> /dev/null; then
198    eval "$(atuin init bash --disable-up-arrow)"
199fi
200
201# Completions (if available)
202for cmd in lune tuios crush lx; do
203    if command -v "$cmd" &> /dev/null; then
204        eval "$("$cmd" completion bash 2>/dev/null || true)"
205    fi
206done