Customize the shell
Add aliases, environment settings, and tool integrations for POSIX sh, Bash, and Zsh.
On this page
Add aliases, environment settings, and tool integrations that load in every shell that supports them.
Prerequisites
- Installed dotfiles and the
dotfilesalias. - The file that owns the setting; see Shell files.
Add a portable alias
-
Edit
~/.config/sh/sh.d/20_aliases.sh. -
Guard the alias with
has, so shells without the tool skip it:has lazygit && alias lg='lazygit'
Put environment variables and PATH entries in ~/.config/sh/profile.d/20_env.sh instead;
use path_add to add a directory once.
Use POSIX syntax only in these files; POSIX sh loads them too.
Add a Bash or Zsh integration
Guard shell-specific code with case $_shell, and cache generated code with source_cache:
case $_shell in
bash | zsh) source_cache "$XDG_CACHE_HOME/shell/direnv.$_shell" direnv hook "$_shell" ;;
esac
source_cache skips missing tools, and regenerates the cache when the tool's executable is newer.
For Zsh-only settings, add a *.zshrc file to ~/.config/zsh/zsh.d/; files load in lexical order.
Add a machine-local module
Create an untracked file, for example ~/.config/sh/sh.d/95_local.sh.
Interactive shells source every *.sh file in sh.d/, and dotfiles status hides untracked files,
so the module stays on this machine.
Add tracked files by name; dotfiles add -A would track the local module.
Reload and verify
Start a new login shell, then check the change:
exec "$SHELL" -l
alias lg
Test POSIX sh separately:
ENV="$XDG_CONFIG_HOME/sh/.shrc" sh -iTrack the change
cd ~
dotfiles status
dotfiles add .config/sh/sh.d/20_aliases.sh
dotfiles commit -m "feat(sh): add lazygit alias"
dotfiles push
Push before the next update; updates fast-forward only.
Undo
Discard an uncommitted change:
cd ~ && dotfiles restore .config/sh/sh.d/20_aliases.sh
Force a cached integration to regenerate by deleting its file under $XDG_CACHE_HOME/shell/.