dotfiles
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDotfiles
Dotfiles
Manage and sync configuration files across machines.
实现多机器间配置文件的管理与同步。
GNU Stow (Simple)
GNU Stow(简易方案)
Setup
配置步骤
bash
undefinedbash
undefinedInstall
安装
brew install stow # macOS
apt install stow # Ubuntu
brew install stow # macOS系统
apt install stow # Ubuntu系统
Create dotfiles directory
创建dotfiles目录
mkdir -p ~/dotfiles
cd ~/dotfiles
undefinedmkdir -p ~/dotfiles
cd ~/dotfiles
undefinedStructure
目录结构
~/dotfiles/
├── zsh/
│ └── .zshrc
├── git/
│ └── .gitconfig
├── nvim/
│ └── .config/
│ └── nvim/
│ └── init.lua
└── tmux/
└── .tmux.conf~/dotfiles/
├── zsh/
│ └── .zshrc
├── git/
│ └── .gitconfig
├── nvim/
│ └── .config/
│ └── nvim/
│ └── init.lua
└── tmux/
└── .tmux.confUsage
使用方法
bash
cd ~/dotfilesbash
cd ~/dotfilesSymlink one package
为单个配置包创建软链接
stow zsh
stow zsh
Symlink all
为所有配置包创建软链接
stow */
stow */
Unlink
移除软链接
stow -D zsh
stow -D zsh
Restow (update)
重新配置(更新)
stow -R zsh
stow -R zsh
Target different directory
指定目标目录创建软链接
stow -t ~ zsh
undefinedstow -t ~ zsh
undefinedChezmoi (Advanced)
Chezmoi(进阶方案)
Setup
配置步骤
bash
undefinedbash
undefinedInstall
安装
brew install chezmoi # or sh -c "$(curl -fsLS get.chezmoi.io)"
brew install chezmoi # 或执行 sh -c "$(curl -fsLS get.chezmoi.io)"
Initialize
初始化
chezmoi init
chezmoi init
Or from existing repo
或从已有仓库初始化
chezmoi init https://github.com/user/dotfiles.git
undefinedchezmoi init https://github.com/user/dotfiles.git
undefinedBasic Usage
基础使用
bash
undefinedbash
undefinedAdd file
添加配置文件
chezmoi add ~/.zshrc
chezmoi add ~/.config/nvim/init.lua
chezmoi add ~/.zshrc
chezmoi add ~/.config/nvim/init.lua
Edit
编辑配置文件
chezmoi edit ~/.zshrc
chezmoi edit ~/.zshrc
See changes
查看变更
chezmoi diff
chezmoi diff
Apply changes
应用变更
chezmoi apply
chezmoi apply
Update from repo
从仓库更新配置
chezmoi update
undefinedchezmoi update
undefinedTemplates
模板功能
bash
undefinedbash
undefined~/.local/share/chezmoi/dot_gitconfig.tmpl
~/.local/share/chezmoi/dot_gitconfig.tmpl
[user]
name = {{ .name }}
email = {{ .email }}
[user]
name = {{ .name }}
email = {{ .email }}
~/.config/chezmoi/chezmoi.toml
~/.config/chezmoi/chezmoi.toml
[data]
name = "John Doe"
email = "john@example.com"
undefined[data]
name = "John Doe"
email = "john@example.com"
undefinedSecrets
敏感信息管理
bash
undefinedbash
undefinedUse 1Password
使用1Password
{{ onepasswordRead "op://Personal/GitHub/token" }}
{{ onepasswordRead "op://Personal/GitHub/token" }}
Use pass
使用pass密码管理器
{{ pass "github/token" }}
{{ pass "github/token" }}
Prompt for value
交互式输入值
{{ promptString "Enter API key" }}
undefined{{ promptString "Enter API key" }}
undefinedGit Bare Repo
Git裸仓库方案
Setup
配置步骤
bash
undefinedbash
undefinedInitialize
初始化裸仓库
git init --bare $HOME/.dotfiles
git init --bare $HOME/.dotfiles
Alias
设置别名
alias dotfiles='git --git-dir=$HOME/.dotfiles --work-tree=$HOME'
alias dotfiles='git --git-dir=$HOME/.dotfiles --work-tree=$HOME'
Ignore untracked
忽略未跟踪文件
dotfiles config --local status.showUntrackedFiles no
undefineddotfiles config --local status.showUntrackedFiles no
undefinedUsage
使用方法
bash
undefinedbash
undefinedAdd files
添加配置文件
dotfiles add ~/.zshrc
dotfiles commit -m "Add zshrc"
dotfiles push
dotfiles add ~/.zshrc
dotfiles commit -m "Add zshrc"
dotfiles push
Clone to new machine
在新机器上克隆仓库
git clone --bare git@github.com:user/dotfiles.git $HOME/.dotfiles
alias dotfiles='git --git-dir=$HOME/.dotfiles --work-tree=$HOME'
dotfiles checkout
undefinedgit clone --bare git@github.com:user/dotfiles.git $HOME/.dotfiles
alias dotfiles='git --git-dir=$HOME/.dotfiles --work-tree=$HOME'
dotfiles checkout
undefinedShell Config
Shell配置
bash
undefinedbash
undefinedAdd to ~/.zshrc or ~/.bashrc
添加到~/.zshrc或~/.bashrc
alias dotfiles='git --git-dir=$HOME/.dotfiles --work-tree=$HOME'
undefinedalias dotfiles='git --git-dir=$HOME/.dotfiles --work-tree=$HOME'
undefinedCommon Dotfiles
常见Dotfiles配置
Essential Files
核心配置文件
~/.zshrc or ~/.bashrc # Shell config
~/.gitconfig # Git config
~/.ssh/config # SSH config
~/.tmux.conf # Tmux config
~/.config/nvim/ # Neovim config
~/.config/starship.toml # Starship prompt~/.zshrc or ~/.bashrc # Shell配置
~/.gitconfig # Git配置
~/.ssh/config # SSH配置
~/.tmux.conf # Tmux配置
~/.config/nvim/ # Neovim配置
~/.config/starship.toml # Starship提示符配置.gitconfig
.gitconfig 示例
ini
[user]
name = Your Name
email = your@email.com
[alias]
co = checkout
br = branch
ci = commit
st = status
lg = log --oneline --graph
[core]
editor = nvim
[init]
defaultBranch = main
[pull]
rebase = trueini
[user]
name = Your Name
email = your@email.com
[alias]
co = checkout
br = branch
ci = commit
st = status
lg = log --oneline --graph
[core]
editor = nvim
[init]
defaultBranch = main
[pull]
rebase = true.zshrc Essentials
.zshrc 核心配置
bash
undefinedbash
undefinedHistory
历史记录设置
HISTFILE=~/.zsh_history
HISTSIZE=10000
SAVEHIST=10000
setopt SHARE_HISTORY
HISTFILE=~/.zsh_history
HISTSIZE=10000
SAVEHIST=10000
setopt SHARE_HISTORY
Aliases
命令别名
alias ll='ls -la'
alias g='git'
alias dc='docker compose'
alias ll='ls -la'
alias g='git'
alias dc='docker compose'
Path
环境变量PATH设置
export PATH="$HOME/.local/bin:$PATH"
export PATH="$HOME/.local/bin:$PATH"
Editor
默认编辑器设置
export EDITOR='nvim'
undefinedexport EDITOR='nvim'
undefinedBootstrap Script
初始化脚本
bash
#!/bin/bashbash
#!/bin/bashbootstrap.sh
bootstrap.sh
set -e
set -e
Install dependencies
安装依赖
if [[ "$OSTYPE" == "darwin"* ]]; then
brew install stow git neovim
fi
if [[ "$OSTYPE" == "darwin"* ]]; then
brew install stow git neovim
fi
Clone dotfiles
克隆dotfiles仓库
git clone https://github.com/user/dotfiles.git ~/dotfiles
git clone https://github.com/user/dotfiles.git ~/dotfiles
Stow all
为所有配置包创建软链接
cd ~/dotfiles
for dir in */; do
stow "$dir"
done
echo "Dotfiles installed!"
undefinedcd ~/dotfiles
for dir in */; do
stow "$dir"
done
echo "Dotfiles installed!"
undefinedBest Practices
最佳实践
- Version control: Always use git
- README: Document setup steps
- Modular: Separate by application
- Secrets: Never commit secrets; use templates or secret managers
- Bootstrap: Create setup script for new machines
- 版本控制:始终使用Git进行版本管理
- README文档:记录配置步骤与说明
- 模块化:按应用程序拆分配置文件
- 敏感信息:绝不要提交敏感信息;使用模板或密钥管理器
- 初始化脚本:为新机器创建一键配置脚本