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        eval "$(mise exec fnox@latest -- fnox activate bash 2>/dev/null || true)"
101    fi
102fi
103
104# ============================================================================
105# History Configuration
106# ============================================================================
107
108# Don't put duplicate lines or lines starting with space in the history
109HISTCONTROL=ignoreboth
110
111# Append to the history file, don't overwrite it
112shopt -s histappend
113
114# History size
115HISTSIZE=10000
116HISTFILESIZE=20000
117
118# Save history to XDG location
119export HISTFILE="$XDG_STATE_HOME/bash/history"
120mkdir -p "$(dirname "$HISTFILE")"
121
122# ============================================================================
123# Shell Options
124# ============================================================================
125
126# Check window size after each command and update LINES/COLUMNS
127shopt -s checkwinsize
128
129# Enable ** globstar (if available)
130shopt -s globstar 2>/dev/null
131
132# Enable programmable completion
133if ! shopt -oq posix; then
134    if [[ -f /usr/share/bash-completion/bash_completion ]]; then
135        source /usr/share/bash-completion/bash_completion
136    elif [[ -f /etc/bash_completion ]]; then
137        source /etc/bash_completion
138    fi
139fi
140
141# ============================================================================
142# Aliases
143# ============================================================================
144
145{{ if ne .chezmoi.hostname "sidhe" }}
146alias zed="zeditor"
147{{ end }}
148
149alias wget="wget --hsts-file=\"$XDG_DATA_HOME/wget-hsts\""
150alias svn="svn --config-dir $XDG_CONFIG_HOME/subversion"
151alias ts="tailscale"
152alias datetime="date +%Y-%m-%d_%H%M%S_%Z"
153alias clip="xclip -selection clipboard"
154alias send="rsync -amzzP"
155alias bat="bat -n --tabs 2"
156alias erase="shred -vzfun 32"
157alias 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'"
158alias us="unsilence -t 15 -as 1.25"
159alias sxiv="sxiv -p"
160alias c="chezmoi"
161alias t="tuios"
162alias ls="lsd"
163alias soft="ssh git.secluded.site"
164alias g="git"
165
166# Modern replacements
167alias ll='ls -la'
168alias la='ls -a'
169
170# ============================================================================
171# Functions
172# ============================================================================
173
174# cheat.sh integration
175cht() {
176    if [[ $# -eq 0 ]]; then
177        echo "Usage: cht <topic> or cht <language>/<query>"
178        return 1
179    fi
180    curl -s "cheat.sh/$*"
181}
182
183# ============================================================================
184# Tool Integrations
185# ============================================================================
186
187# Starship prompt
188if command -v starship &> /dev/null; then
189    eval "$(starship init bash)"
190fi
191
192# Atuin history
193if command -v atuin &> /dev/null; then
194    eval "$(atuin init bash --disable-up-arrow)"
195fi
196
197# Completions (if available)
198for cmd in lune tuios crush lx; do
199    if command -v "$cmd" &> /dev/null; then
200        eval "$("$cmd" completion bash 2>/dev/null || true)"
201    fi
202done