使用Dotbot管理dotfiles
本文通过
为什么选择Dotbot?
不需要自己编写dotfiles配置文件和相关脚本,更方便使用和管理。
dotbot特点如下:
- 只需要一个配置文件(
install.conf.yaml) - 只需要一行命令即可在不同设备安装符号链接
- 可以作为git submodule使用
使用Git添加子模块Dotbot
1 | |
现在开始编辑配置文件install.conf.yaml
1 | |
Default options for plugins can be specified so that options don't have to be repeated many times.
Defaults apply to all commands that come after setting the defaults. Defaults can be set multiple times; each change replaces the defaults with a new set of options.
Default: 这里设置了create和relink两个参数,更多参数信息参考这里。
| Parameter | Explanation |
|---|---|
create |
When true, create parent directories to the link as needed. (default: false) |
relink |
Removes the old target if it's a symlink (default: false) |
Clean commands specify directories that should be checked for dead symbolic links. These dead links are removed automatically. Only dead links that point to somewhere within the dotfiles directory are removed unless the
forceoption is set totrue.
Clean: 根据需求设置即可。
Link commands specify how files and directories should be symbolically linked.
Link:
这是经常修改的地方,定义如何链接我们的dotfiles。这里以~/.zshrc和~/.vimrc举例。
Shell commands specify shell commands to be run. Shell commands are run in the base directory
在这里是安装submodules。
将dotfiles移至仓库
这里以~/.zshrc和~/.vimrc举例。
1 | |
接着可以删除
~/下的.vimrc和.zshrc文件。(⚠️注意备份)
运行安装脚本
现在我们可以通过./install测试是否正常运行。正常情况下将会看到类似👇的信息:
1
2
3
4
5
6
7
8
9./install
All targets have been cleaned
Creating link ~/.zshrc -> ~/.dotfiles/zshrc
Creating link ~/.vimrc -> ~/.dotfiles/vimrc
All links have been set up
Installing submodules [git submodule update --init --recursive]
All commands have been executed
==> All tasks executed successfully
commit + push -> 远程仓库
假设在GitHub上创建了名为dotfiles的仓库
1 | |
在其他机器上使用仓库里的配置文件
1 | |
如果仓库有更新则可通过下面命令更新本地配置:
1 | |
总结
通过Dotbot和Git可以方便我们维护dotfiles并通过git仓库共享配置。