GNU Stow Basics
Understanding symlink management with GNU Stow for modular dotfile organization.
Overview
GNU Stow is the foundation of DotClaude's modular architecture, enabling safe, reversible configuration management through symbolic links.
How Stow Works
Symlink Management
Stow creates symbolic links from a source directory to a target directory:
bash
# Basic stow operation
cd ~/dotfiles
stow -t ~ stow/zsh
# This creates symlinks:
# ~/.zshrc -> ~/dotfiles/stow/zsh/.zshrcPackage Structure
Each configuration is organized as a "package":
stow/
├── git/
│ └── .gitconfig
├── zsh/
│ └── .zshrc
├── neovim/
│ └── .config/
│ └── nvim/
└── tmux/
└── .tmux.confDotClaude Package Organization
Core Packages
- git - Git configuration with modern diff tools
- zsh - Shell enhancement with Oh-My-Zsh
- neovim - Modern editor configuration
- tmux - Terminal multiplexing setup
Support Packages
- aliases - Centralized alias management
- environment - PATH and environment variables
- rust-tools - Modern CLI tool configurations
Safety Scripts
DotClaude provides wrapper scripts for safe stow operations:
Package Management
bash
# Apply a package safely
./scripts/stow-package.sh zsh
# Remove a package
./scripts/unstow-package.sh zsh
# Check package status
./scripts/check-package.sh zshBackup & Restore
bash
# Backup before applying
./scripts/backup.sh zsh
# Restore if needed
./scripts/restore.sh zshStow Commands
Basic Operations
bash
# Apply package
stow -t ~ package-name
# Remove package
stow -D -t ~ package-name
# Simulate (dry run)
stow -n -t ~ package-name
# Verbose output
stow -v -t ~ package-nameAdvanced Usage
bash
# Force operation (overwrite conflicts)
stow --adopt -t ~ package-name
# Specify stow directory
stow -d ~/dotfiles/stow -t ~ package-name
# Target specific directory
stow -t ~/.config config-packageConflict Resolution
Handling Conflicts
When stow encounters existing files:
- Backup - Always backup existing files first
- Adopt - Use
--adoptto take ownership of existing files - Review - Check differences before applying
- Merge - Manually merge conflicting configurations
Example Conflict Resolution
bash
# Backup existing file
cp ~/.zshrc ~/.zshrc.backup
# Apply package with adoption
stow --adopt -t ~ zsh
# Review and merge differences
diff ~/.zshrc.backup ~/.zshrcBest Practices
Package Design
- Modularity - Keep packages focused and independent
- Structure - Mirror target directory structure
- Documentation - Include README for complex packages
- Testing - Test packages individually
Safety Measures
- Always Backup - Backup before applying changes
- Dry Run - Use
-nflag to preview changes - Incremental - Apply packages one at a time
- Verification - Test functionality after applying
Maintenance
- Regular Updates - Keep packages up to date
- Cleanup - Remove unused packages
- Documentation - Update package documentation
- Version Control - Track all changes in git
Troubleshooting
Common Issues
- Permission Errors - Check file permissions
- Broken Links - Verify source file existence
- Path Conflicts - Resolve directory structure issues
- Stow Conflicts - Handle overlapping packages
Debugging Commands
bash
# Check stow status
stow -n -v -t ~ package-name
# List stow links
find ~ -type l -ls | grep dotfiles
# Verify link targets
ls -la ~/.zshrcIntegration with DotClaude
Automated Scripts
DotClaude provides automation for common stow operations:
- Package installation and removal
- Backup and restore procedures
- Conflict detection and resolution
- Health checks and validation
Safety First Approach
All stow operations in DotClaude are:
- Non-destructive - Always backup first
- Reversible - Easy rollback procedures
- Tested - Validated before system-wide deployment
- Documented - Clear procedures and troubleshooting