Virtual Environments
Virtual environments allow you to create isolated dotfiles configurations for different projects, similar to Python’s venv, pyenv, or Hermit.
Overview
Section titled “Overview”Instead of a single global dotfiles configuration, you can create project-specific environments with their own:
- Tool configurations
- Generated shell scripts
- Installed binaries
- XDG configuration files
Creating an Environment
Section titled “Creating an Environment”# Create with default name 'env' in current directorydotfiles env create
# Create with custom namedotfiles env create my-env
# Create at absolute pathdotfiles env create /path/to/project/.devenvThis creates:
env/├── source # POSIX shell activation script├── source.ps1 # PowerShell activation script├── dotfiles.config.ts # Dotfiles configuration├── .config/ # XDG_CONFIG_HOME for tool configs└── tools/ # Tool configuration directoryActivating an Environment
Section titled “Activating an Environment”Bash/Zsh:
source env/sourcePowerShell:
. .\env\source.ps1When activated, the following environment variables are set:
| Variable | Value |
|---|---|
DOTFILES_ENV_DIR | Absolute path to environment |
DOTFILES_ENV_NAME | Environment directory name |
XDG_CONFIG_HOME | $DOTFILES_ENV_DIR/.config |
PATH | Prepended with environment’s bin dir |
Using an Activated Environment
Section titled “Using an Activated Environment”Once activated, all dotfiles commands use the environment’s configuration automatically:
source env/source
# These all use env/dotfiles.config.ts automaticallydotfiles generatedotfiles installdotfiles update fdNo need to pass --config - the CLI detects DOTFILES_ENV_DIR and uses its dotfiles.config.ts.
Adding Tools
Section titled “Adding Tools”Create tool configuration files in the tools/ directory:
source env/source
cat > env/tools/fd.tool.ts << 'EOF'import { defineTool } from '@alexgorbatchev/dotfiles';
export default defineTool((install) => install('github-release', { repo: 'sharkdp/fd' }) .bin('fd'));EOF
dotfiles generatedotfiles install fdDeactivating
Section titled “Deactivating”dotfiles-deactivateThis restores the previous PATH and XDG_CONFIG_HOME values.
Deleting an Environment
Section titled “Deleting an Environment”# Delete default 'env' directorydotfiles env delete
# Delete specific environmentdotfiles env delete my-env
# Force delete without confirmationdotfiles env delete --forceUse Cases
Section titled “Use Cases”Project-Specific Tools
Section titled “Project-Specific Tools”Keep project tools isolated from your global configuration:
cd ~/projects/data-sciencedotfiles env createsource env/source
# Add project-specific toolscat > env/tools/jupyter.tool.ts << 'EOF'import { defineTool } from '@alexgorbatchev/dotfiles';export default defineTool((install) => install('manual').bin('jupyter') .zsh((shell) => shell.aliases({ jn: 'jupyter notebook', jl: 'jupyter lab' })));EOF
dotfiles generateTeam Environments
Section titled “Team Environments”Share tool configurations with your team:
cd ~/work/team-projectdotfiles env create .devenv
# Configure shared tools# ...
# Add to version controlecho ".devenv/.generated" >> .gitignoregit add .devenv/dotfiles.config.ts .devenv/tools/ .devenv/source .devenv/source.ps1git commit -m "Add development environment"Team members then run:
git clone <repo>cd team-projectsource .devenv/sourcedotfiles installMultiple Environments
Section titled “Multiple Environments”Different projects can have different tool versions:
# Project A uses older toolscd ~/projects/legacydotfiles env createsource env/source# Configure tools...
# Project B uses latestcd ~/projects/moderndotfiles env createsource env/source# Configure different versions...XDG Configuration Isolation
Section titled “XDG Configuration Isolation”The environment sets XDG_CONFIG_HOME to isolate tool configuration files:
source env/sourceecho $XDG_CONFIG_HOME# Tools that respect XDG will store config here# e.g., ~/.config/nvim becomes env/.config/nvimThis prevents activated environments from affecting global tool configurations.
Generated Files
Section titled “Generated Files”After running dotfiles generate, the environment contains:
env/├── .generated/│ ├── shell-scripts/│ │ ├── main.zsh│ │ ├── main.bash│ │ └── main.ps1│ ├── user-bin/│ │ └── <tool shims>│ └── binaries/│ └── <installed tools>├── source├── source.ps1├── dotfiles.config.ts├── .config/└── tools/The activation script sources the generated shell scripts and adds user-bin to PATH.