Skip to content

fix(install): detect shell rc files for ZDOTDIR and macOS login shells#24

Merged
guodong-sq merged 1 commit intoblock:mainfrom
bezhermoso:bezalel/shell-home
Feb 27, 2026
Merged

fix(install): detect shell rc files for ZDOTDIR and macOS login shells#24
guodong-sq merged 1 commit intoblock:mainfrom
bezhermoso:bezalel/shell-home

Conversation

@bezhermoso
Copy link
Contributor

@bezhermoso bezhermoso commented Feb 25, 2026

Summary

The installer's configure_shell_rc() hardcoded $HOME/.zshrc and $HOME/.bashrc as the only rc files to configure. This silently did nothing (no snippet appended, no warning shown) in two common scenarios:

  1. ZDOTDIR is set — zsh reads $ZDOTDIR/.zshrc, not $HOME/.zshrc. This is common with dotfile managers (chezmoi, stow, yadm) and users who keep $HOME clean via XDG-style layouts.
  2. macOS Bash with only .bash_profile — macOS Terminal.app and iTerm2 open login shells by default, which source ~/.bash_profile, not ~/.bashrc. Users without a .bashrc were silently skipped.

Changes

install.shconfigure_shell_rc()

  • Zsh detection now respects ZDOTDIR: checks ${ZDOTDIR:-$HOME}/.zshrc
  • Bash detection falls back from .bashrc to .bash_profile (first existing file wins)
  • Emits a warn when no rc file is found at all, with the exact line to add manually

install.sh — Legacy migration loop

  • The for rc_file in ... loop that migrates .config/wt.wt references now checks the same expanded set of paths: ${ZDOTDIR:-$HOME}/.zshrc, $HOME/.bashrc, $HOME/.bash_profile
  • When ZDOTDIR is unset, the first and second entries both resolve under $HOME; the grep guard prevents double-processing

install.sh — Post-install banner

  • The "Reload your shell" instruction now dynamically shows the correct file path instead of the hardcoded source ~/.zshrc # or ~/.bashrc
  • Replaces $HOME prefix with ~ for a clean display

wt.sh_wt_ensure_sourced() error messages

  • Zsh block: ~/.zshrc${ZDOTDIR:-~}/.zshrc
  • Bash block: ~/.bashrc~/.bashrc (or ~/.bash_profile)

Test plan

  • ./test/bats/bin/bats test/unit/ test/integration/ test/e2e/ — 167/168 pass (1 pre-existing failure in wt-remove --merged unrelated to this change)
  • Manual: set ZDOTDIR to a temp dir containing a .zshrc, run installer, verify snippet lands in the correct file
  • Manual: on macOS with only ~/.bash_profile (no ~/.bashrc), run installer, verify snippet lands in .bash_profile
  • Manual: with neither rc file present, verify warning is printed

🤖 Generated with Claude Code

The installer's configure_shell_rc() hardcoded $HOME/.zshrc and
$HOME/.bashrc, which silently failed (no snippet, no warning) when:

1. ZDOTDIR is set — zsh reads $ZDOTDIR/.zshrc, not $HOME/.zshrc.
   Common with dotfile managers (chezmoi, stow) and XDG-clean setups.
2. macOS Bash with only .bash_profile — macOS terminals open login
   shells, which read ~/.bash_profile not ~/.bashrc.

Changes:
- configure_shell_rc() now checks ${ZDOTDIR:-$HOME}/.zshrc for zsh
  and falls back from .bashrc to .bash_profile for bash
- Warns when no rc file is found at all
- Legacy migration loop checks the same expanded set of paths
- Post-install banner dynamically shows the correct file to source
- wt.sh error messages reference the correct rc file paths

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@guodong-sq guodong-sq merged commit cc527b1 into block:main Feb 27, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants