unify zsh+bash shell config; fix zsh startup

Support either shell as the login shell via stow selection (merges the
bashed branch in). shell/ holds shared POSIX env + interactive config;
each shell loads its own rc natively.

- zsh: add .zshenv (sets ZDOTDIR+env early), rename rc -> .zshrc, add
  login-only .zprofile (pyenv --path)
- bash: add ~/.bash_profile + ~/.bashrc stubs, .config/bash/{rc,prompt}
- shell: profile is POSIX env-only (no zsh-rc source); path rewritten
  POSIX + idempotent (flat ~/.local/bin, no subdir recursion); new
  interactive sources aliases/functions + pyenv shims
- drop dead shell/.zprofile symlink; move ZDOTDIR out of exports

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-26 17:46:10 +02:00
parent a6a3d3a759
commit 0253a46882
13 changed files with 293 additions and 20 deletions
+57
View File
@@ -0,0 +1,57 @@
# My personal dotfiles
To be used with GNU stow.
Goal is a clean-as-possible home directory.
As much as possible in standard `.config/`, `.local/` and so on.
## Shell architecture (multi-shell)
The config supports **both zsh and bash** from one branch. Pick the login shell
by which package you `stow`; `shell/` is always stowed. (There used to be a
separate `bashed` branch — retired; do not recreate it.)
Split by *role*:
- **`shell/`** (shared) — POSIX, shell-agnostic.
- `exports`, `path` — environment. `path` is idempotent (safe to source twice).
- `aliases`, `functions` — interactive bits, POSIX-safe.
- `interactive` — sources `aliases`/`functions`/`extra` + pyenv shims. Loaded
by each shell's own rc (brace expansion OK; only zsh/bash source it).
- `profile` — POSIX **login env only** (no brace expansion, no rc source).
`~/.profile` symlinks to it.
- **`zsh/`** — `~/.zshenv` (sets `ZDOTDIR`+env, runs for *every* zsh),
`$ZDOTDIR/.zshrc` (interactive, sources `shell/interactive`),
`$ZDOTDIR/.zprofile` (login-only, pyenv `--path`).
- **`bash/`** — `~/.bash_profile` (login → sources `~/.bashrc` + pyenv `--path`),
`~/.bashrc` (sources `~/.profile` for env, then `~/.config/bash/rc`),
`~/.config/bash/rc` (interactive, sources `shell/interactive` + bash bits),
`prompt`.
Invariants worth keeping:
- `ZDOTDIR` belongs in `~/.zshenv` only — it must be set before zsh reads any
rc file, so `exports` is too late.
- Env must reach **non-login interactive** shells: zsh gets it via `.zshenv`
(always runs); bash gets it because `.bashrc` re-sources `~/.profile`
(idempotent). Don't move env loading out of those two spots.
- Prompts are necessarily per-shell (`%n@%M` vs `\u@\h`); keep them split.
## Known issues / TODO (next session)
Remaining from the 2026-06-26 review (zsh/bash startup items already fixed):
1. **Clean-home goal leaks:**
- `psql/rc`: `HISTFILE ~/.psql_history-:DBNAME` writes a dotfile to `$HOME`.
Redirect under `~/.cache`.
- `git/config`: `excludesfile = ~/.gitignore`, `attributesfile = ~/.gitattributes`.
Move to `~/.config/git/{ignore,attributes}` (git reads `ignore` there by default).
2. **History dirs not created.** `HISTFILE` points at `$XDG_CACHE_HOME/shell/history`,
but zsh/bash won't `mkdir` the parent, so history is silently dropped. Need a
bootstrap/`mkdir -p`. (The python startup script already does its own mkdir.)
3. **Dead config.** alias `f="$FILE"``$FILE` is never set (empty alias);
`functions` file is empty; `git/config` carries macOS-only settings
(`trustctime`, `precomposeunicode`, mac comments) — dead weight on Arch.
`bash/.config/bash/rc` also keeps Homebrew/macOS completion blocks (guarded,
harmless, but droppable).
+8
View File
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
# Bash login shell. Everything a non-login shell gets lives in ~/.bashrc, so
# source it, then add login-only bits.
[ -r ~/.bashrc ] && . ~/.bashrc
# pyenv shims dir (login only); PYENV_ROOT comes from ~/.config/shell/exports.
command -v pyenv >/dev/null 2>&1 && eval "$(pyenv init --path)"
+7
View File
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
# Loaded by every interactive bash, and by login bash via ~/.bash_profile.
# Source env first (idempotent — covers non-login interactive shells that bash
# would otherwise start without it), then the real interactive config.
[ -r ~/.profile ] && . ~/.profile
[ -r ~/.config/bash/rc ] && . ~/.config/bash/rc
+123
View File
@@ -0,0 +1,123 @@
#!/usr/bin/env bash
# Source: https://github.com/mathiasbynens/dotfiles/
# Shell prompt based on the Solarized Dark theme.
# Screenshot: http://i.imgur.com/EkEtphC.png
# Heavily inspired by @necolass prompt: https://github.com/necolas/dotfiles
# iTerm → Profiles → Text → use 13pt Monaco with 1.1 vertical spacing.
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then
export TERM='gnome-256color';
elif infocmp xterm-256color >/dev/null 2>&1; then
export TERM='xterm-256color';
fi;
prompt_git() {
local s='';
local branchName='';
# Check if the current directory is in a Git repository.
git rev-parse --is-inside-work-tree &>/dev/null || return;
# Check for what branch were on.
# Get the short symbolic ref. If HEAD isnt a symbolic ref, get a
# tracking remote branch or tag. Otherwise, get the
# short SHA for the latest commit, or give up.
branchName="$(git symbolic-ref --quiet --short HEAD 2> /dev/null || \
git describe --all --exact-match HEAD 2> /dev/null || \
git rev-parse --short HEAD 2> /dev/null || \
echo '(unknown)')";
# Early exit for Chromium & Blink repo, as the dirty check takes too long.
# Thanks, @paulirish!
# https://github.com/paulirish/dotfiles/blob/dd33151f/.bash_prompt#L110-L123
repoUrl="$(git config --get remote.origin.url)";
if grep -q 'chromium/src.git' <<< "${repoUrl}"; then
s+='*';
else
# Check for uncommitted changes in the index.
if ! $(git diff --quiet --ignore-submodules --cached); then
s+='+';
fi;
# Check for unstaged changes.
if ! $(git diff-files --quiet --ignore-submodules --); then
s+='!';
fi;
# Check for untracked files.
if [ -n "$(git ls-files --others --exclude-standard)" ]; then
s+='?';
fi;
# Check for stashed files.
if $(git rev-parse --verify refs/stash &>/dev/null); then
s+='$';
fi;
fi;
[ -n "${s}" ] && s=" [${s}]";
echo -e "${1}${branchName}${2}${s}";
}
if tput setaf 1 &> /dev/null; then
tput sgr0; # reset colors
bold=$(tput bold);
reset=$(tput sgr0);
# Solarized colors, taken from http://git.io/solarized-colors.
black=$(tput setaf 0);
blue=$(tput setaf 33);
cyan=$(tput setaf 37);
green=$(tput setaf 64);
orange=$(tput setaf 166);
purple=$(tput setaf 125);
red=$(tput setaf 124);
violet=$(tput setaf 61);
white=$(tput setaf 15);
yellow=$(tput setaf 136);
else
bold='';
reset="\e[0m";
black="\e[1;30m";
blue="\e[1;34m";
cyan="\e[1;36m";
green="\e[1;32m";
orange="\e[1;33m";
purple="\e[1;35m";
red="\e[1;31m";
violet="\e[1;35m";
white="\e[1;37m";
yellow="\e[1;33m";
fi;
# Highlight the user name when logged in as root.
if [[ "${USER}" == "root" ]]; then
userStyle="${red}";
else
userStyle="${orange}";
fi;
# Highlight the hostname when connected via SSH.
if [[ "${SSH_TTY}" ]]; then
hostStyle="${bold}${red}";
else
hostStyle="${yellow}";
fi;
# Set the terminal title and prompt.
PS1="\[\033]0;\W\007\]"; # working directory base name
PS1+="\[${bold}\]\n"; # newline
PS1+="\[${userStyle}\]\u"; # username
PS1+="\[${white}\] at ";
PS1+="\[${hostStyle}\]\h"; # host
PS1+="\[${white}\] in ";
PS1+="\[${green}\]\w"; # working directory full path
PS1+="\$(prompt_git \"\[${white}\] on \[${violet}\]\" \"\[${blue}\]\")"; # Git repository details
PS1+="\n";
PS1+="\[${white}\]\$ \[${reset}\]"; # `$` (and reset color)
export PS1;
PS2="\[${yellow}\]→ \[${reset}\]";
export PS2;
+45
View File
@@ -0,0 +1,45 @@
#!/usr/bin/env bash
# Mostly copied from: https://github.com/mathiasbynens/dotfiles/
# Shared interactive config (aliases, functions, pyenv shims):
[ -r ~/.config/shell/interactive ] && source ~/.config/shell/interactive
# Bash-specific:
[ -f ~/.config/bash/prompt ] && source ~/.config/bash/prompt
# Case-insensitive globbing (used in pathname expansion)
shopt -s nocaseglob;
# Append to the Bash history file, rather than overwriting it
shopt -s histappend;
# Autocorrect typos in path names when using `cd`
shopt -s cdspell;
# Enable some Bash 4 features when possible:
# * `autocd`, e.g. `**/qux` will enter `./foo/bar/baz/qux`
# * Recursive globbing, e.g. `echo **/*.txt`
for option in autocd globstar; do
shopt -s "$option" 2> /dev/null;
done;
# Add tab completion for many Bash commands
if which brew &> /dev/null && [ -r "$(brew --prefix)/etc/profile.d/bash_completion.sh" ]; then
# Ensure existing Homebrew v1 completions continue to work
export BASH_COMPLETION_COMPAT_DIR="$(brew --prefix)/etc/bash_completion.d";
source "$(brew --prefix)/etc/profile.d/bash_completion.sh";
elif [ -f /etc/bash_completion ]; then
source /etc/bash_completion;
fi;
# Enable tab completion for `g` by marking it as an alias for `git`
if type _git &> /dev/null; then
complete -o default -o nospace -F _git g;
fi;
# Add tab completion for SSH hostnames based on ~/.ssh/config, ignoring wildcards
[ -e "$HOME/.ssh/config" ] && complete -o "default" -o "nospace" -W "$(grep "^Host" ~/.ssh/config | grep -v "[?*]" | cut -d " " -f2- | tr ' ' '\n')" scp sftp ssh;
# Add tab completion for `defaults read|write NSGlobalDomain`
# You could just use `-g` instead, but I like being explicit
complete -W "NSGlobalDomain" defaults;
+2 -2
View File
@@ -33,5 +33,5 @@ export PYTHON_HISTFILE="${XDG_CACHE_HOME:-$HOME/.cache}/python/history"
# Wget config file # Wget config file
export WGETRC="${XDG_CONFIG_HOME:-$HOME/.config}/wget/rc" export WGETRC="${XDG_CONFIG_HOME:-$HOME/.config}/wget/rc"
# ZSH directory # NOTE: ZDOTDIR lives in ~/.zshenv, not here. It must be set before zsh reads
export ZDOTDIR="${XDG_CONFIG_HOME:-$HOME/.config}/zsh" # any rc file, and this file is sourced too late for that.
+12
View File
@@ -0,0 +1,12 @@
#!/bin/sh
# Shared interactive shell config. Sourced by both zsh ($ZDOTDIR/.zshrc) and
# bash (~/.config/bash/rc). Only ever loaded by zsh/bash, so brace expansion is
# fine here (unlike the POSIX `profile`).
for _file in "${XDG_CONFIG_HOME:-$HOME/.config}"/shell/{aliases,functions,extra}; do
[ -r "$_file" ] && . "$_file"
done
unset _file
# pyenv interactive shims (pyenv init - autodetects the running shell):
command -v pyenv >/dev/null 2>&1 && eval "$(pyenv init -)"
+6 -2
View File
@@ -1,4 +1,8 @@
#!/bin/sh #!/bin/sh
# Adds `~/.local/bin` to $PATH # Prepend ~/.local/bin to $PATH (POSIX, idempotent — safe to source twice).
export PATH="$PATH:${$(find ~/.local/bin -type d -printf %p:)%%:}" case ":$PATH:" in
*":$HOME/.local/bin:"*) ;;
*) [ -d "$HOME/.local/bin" ] && PATH="$HOME/.local/bin:$PATH" ;;
esac
export PATH
+11 -15
View File
@@ -1,17 +1,13 @@
#!/bin/sh #!/bin/sh
# Load the shell dotfiles, and then some: # POSIX login environment. Sourced directly by a /bin/sh login (display
# * ~/.path can be used to extend `$PATH`. # managers, plain sh) and indirectly by bash via ~/.bashrc. Env only — no
# * ~/.extra can be used for other settings you dont want to commit. # brace expansion (dash doesn't expand it), no shell-specific rc.
for file in ~/.config/shell/{path,exports,aliases,functions,extra}; do #
[ -r "$file" ] && [ -f "$file" ] && source "$file"; # Interactive config (aliases, functions, prompt) is loaded by each shell's
done; # own rc via ~/.config/shell/interactive, not here.
unset file; for _name in path exports; do
_file="${XDG_CONFIG_HOME:-$HOME/.config}/shell/$_name"
source ~/.config/zsh/rc [ -r "$_file" ] && . "$_file"
done
# Setup pyenv, if it is installed: unset _name _file
if [ -x "$(command -v pyenv)" ]; then
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
fi
-1
View File
@@ -1 +0,0 @@
.config/shell/profile
+5
View File
@@ -0,0 +1,5 @@
#!/bin/sh
# zsh login shell only. PATH-level init that belongs to login (pyenv shims dir).
# PYENV_ROOT is exported earlier in ~/.config/shell/exports.
command -v pyenv >/dev/null 2>&1 && eval "$(pyenv init --path)"
@@ -1,6 +1,10 @@
# Luke's config for the Zoomer Shell # Luke's config for the Zoomer Shell
# Source (mainly): https://github.com/LukeSmithxyz/voidrice/ # Source (mainly): https://github.com/LukeSmithxyz/voidrice/
# Shared interactive config (aliases, functions, pyenv shims):
[ -r "${XDG_CONFIG_HOME:-$HOME/.config}/shell/interactive" ] && \
. "${XDG_CONFIG_HOME:-$HOME/.config}/shell/interactive"
# Enable colors and change prompt: # Enable colors and change prompt:
autoload -U colors && colors # Load colors autoload -U colors && colors # Load colors
PS1="%B%{$fg[red]%}[%{$fg[yellow]%}%n%{$fg[green]%}@%{$fg[blue]%}%M %{$fg[magenta]%}%~%{$fg[red]%}]%{$reset_color%}$%b " PS1="%B%{$fg[red]%}[%{$fg[yellow]%}%n%{$fg[green]%}@%{$fg[blue]%}%M %{$fg[magenta]%}%~%{$fg[red]%}]%{$reset_color%}$%b "
+13
View File
@@ -0,0 +1,13 @@
#!/bin/sh
# Read first by zsh for EVERY shell (login or not), so this is the only place
# ZDOTDIR can be set early enough to redirect where zsh looks for its rc files.
export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
export ZDOTDIR="$XDG_CONFIG_HOME/zsh"
# Shared POSIX environment (idempotent):
for _name in path exports; do
_file="$XDG_CONFIG_HOME/shell/$_name"
[ -r "$_file" ] && . "$_file"
done
unset _name _file