A Go utility that scans for dotlink.yaml configuration files and creates symbolic links for configuration management.
Features
β¨ Smart Config Parsing
- YAML-based configuration format
- Support for directory and file-level linking
- Environment variable expansion (e.g.,
$HOME/.zsh)
π Flexible Linking
- Link entire directories to target locations
- Link individual files with custom target paths
- Automatic parent directory creation
- Safe overwriting of existing symlinks
π Enhanced Logging
- Emoji-based visual feedback
- Debug-level logging for troubleshooting
- Information messages for key operations
- Error handling with clear messages
π§ͺ Comprehensive Testing
- Full test coverage of core functionality
- Tests for config parsing, path expansion, and linking
- Dry-run mode support for safe testing
Create a dotlink.yaml file in your configuration directory:
link:
to: $HOME/.zsh
files:
- file: .zshrc
to: $HOME/.zshrc
- file: .zsh_profile
to: $HOME/.zsh_profile
Configuration Options
- link.to: Directory where the config directory will be linked
- files: List of individual files to link
- file: Path relative to the dotlink.yaml directory
- to: Target path where the file will be linked (supports environment variables)
Usage
Basic Usage
./dotlink
This will:
- Scan
$DOTLINK_ROOT (defaults to $HOME/.custom) recursively
- Find all
dotlink.yaml files
- Create symbolic links according to each configuration
Environment Variables
DOTLINK_ROOT: Root directory to scan (default: $HOME/.custom)
Implementation Details
Core Components
config.go
- DotlinkConfig: Main configuration structure
- LoadConfig(): Parses YAML configuration files
- ExpandPath(): Expands environment variables in paths
linker.go
- Linker: Main linking orchestrator
- LinkDirectory(): Creates directory-level symlinks
- LinkFile(): Creates file-level symlinks
- ProcessConfig(): Orchestrates the full linking process
main.go
- Scans for dotlink.yaml files
- Iterates and processes each configuration
- Provides user-friendly emoji-based logging
Logging with Emojis
The tool uses emojis to provide clear visual feedback:
- π Scanning operations
- β¨ Found files
- π File system operations
- π Directory linking
- π File operations
- π Successful links created
- π Config processing
- β
Successful completion
- β Errors
- β οΈ Warnings
Testing
Run the test suite:
go test -v
Test Coverage
TestLoadConfig: YAML parsing
TestGetConfigDir: Configuration directory extraction
TestExpandPath: Environment variable expansion
TestLinkerLinkFile: File symlinking
TestLinkerLinkDirectory: Directory symlinking
TestLinkerDryRun: Dry-run mode verification
TestProcessConfig: Full configuration processing
TestLoadConfigInvalidYAML: Error handling
Example Workflow
-
Create a configuration directory structure:
~/.custom/zsh/
βββ dotlink.yaml
βββ .zshrc
βββ .zsh_profile
-
Create dotlink.yaml:
link:
to: $HOME/.zsh
files:
- file: .zshrc
to: $HOME/.zshrc
- file: .zsh_profile
to: $HOME/.zsh_profile
-
Run dotlink:
DOTLINK_ROOT=$HOME/.custom ./dotlink
-
Result:
$HOME/.zsh β symlink to ~/.custom/zsh
$HOME/.zshrc β symlink to ~/.custom/zsh/.zshrc
$HOME/.zsh_profile β symlink to ~/.custom/zsh/.zsh_profile
Dependencies
gopkg.in/yaml.v3: YAML parsing
github.com/charmbracelet/log: Enhanced logging with colors and emojis
Building
go build -o dotlink
Error Handling
The tool handles various error conditions gracefully:
- Missing source files
- Invalid YAML configuration
- File system permission issues
- Existing symlink conflicts
All errors are logged with context to help with troubleshooting.