Skip to content

Instantly share code, notes, and snippets.

@simoninglis
Created February 5, 2026 07:00
Show Gist options
  • Select an option

  • Save simoninglis/0429455ea41188ea6c6c971fe33ef6ac to your computer and use it in GitHub Desktop.

Select an option

Save simoninglis/0429455ea41188ea6c6c971fe33ef6ac to your computer and use it in GitHub Desktop.
Modular .bashrc with .bashrc.d/ - shell configuration pattern for use with GNU Stow

Modular .bashrc with .bashrc.d/

A pattern for organising shell configuration into focused, manageable files. Works especially well with GNU Stow for dotfiles.

The sourcing loop

Add this to the end of your ~/.bashrc:

# Source additional shell configurations
if [ -d "$HOME/.bashrc.d" ]; then
    for config in "$HOME/.bashrc.d"/*.sh; do
        [ -r "$config" ] && source "$config"
    done
fi

Directory structure

Use numbered prefixes to control load order:

~/.bashrc.d/
├── 10-clipboard.sh
├── 20-fzf.sh
├── 21-zoxide.sh
├── 22-exa.sh
├── 25-nvim.sh
├── 30-project-workflow.sh
├── 40-nvm.sh
└── 70-powershell.sh
  • Lower numbers load first
  • Gaps give room for new files without renumbering
  • 10s: core utilities, 20s: CLI tools, 30s: workflow, 40s: language runtimes

Example: 22-exa.sh

#!/bin/bash
# 22-exa.sh - modern ls replacement

if command -v exa &> /dev/null; then
    alias ls='exa'
    alias l='exa -la --icons'
    alias t='exa --tree --icons'
fi

Example: 25-nvim.sh

#!/bin/bash
# 25-nvim.sh - editor configuration

if command -v nvim &> /dev/null; then
    export EDITOR=nvim
    export VISUAL=nvim
    alias vi='nvim'
    alias vim='nvim'
fi

With GNU Stow

The real power comes from combining with Stow. Each Stow package can contribute its own .bashrc.d/ file:

~/dotfiles/nvim/
├── .bashrc.d/
│   └── 25-nvim.sh      # shell integration
└── .config/
    └── nvim/
        └── init.lua    # editor config

Run stow nvim and both get symlinked. Unstow and the shell config disappears too.

Multiple packages merge into one .bashrc.d/ directory. No conflicts.


Full write-up: https://simoninglis.com/posts/modular-bashrc

Previous article: GNU Stow for dotfiles

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment