使用Dotbot管理dotfiles
本文最后更新于 617 天前,其中的信息可能已经有所发展或是发生改变。

通过dotbot管理dotfiles并搭建dotfiles仓库。

为什么选择Dotbot?

不需要自己编写dotfiles配置文件和相关脚本,更方便使用和管理。

dotbot特点如下:

  • 只需要一个配置文件(install.conf.yaml)
  • 只需要一行命令即可在不同设备安装符号链接
  • 可以作为git submodule使用

使用Git添加子模块Dotbot

mkdir ~/.dotfiles # Create project directory
cd ~/.dotfiles # replace with the path to your dotfiles
git init # initialize repository if needed
git submodule add https://github.com/anishathalye/dotbot
git config -f .gitmodules submodule.dotbot.ignore dirty # ignore dirty commits in the submodule
cp dotbot/tools/git-submodule/install .
touch install.conf.yaml

现在开始编辑配置文件install.conf.yaml

- defaults:
    link:
      create: true
      relink: true

- clean: ['~']

- link:
    ~/.zshrc: zshrc
    ~/.vimrc: vimrc

- shell:
    - [git submodule update --init --recursive, Installing submodules]

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两个参数,更多参数信息参考这里

ParameterExplanation
createWhen true, create parent directories to the link as needed. (default: false)
relinkRemoves 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 force option is set to true.

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举例。

cp ~/.vimrc ./vimrc
cp ~/.zshrc ./zshrc

接着可以删除~/下的.vimrc.zshrc文件。(⚠️注意备份)

运行安装脚本

现在我们可以通过./install测试是否正常运行。正常情况下将会看到类似👇的信息:

./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的仓库

git add --all
git remote add origin git@github.com:username/dotfiles.git
# git remote -v 查看是否更新remote repo信息
# git pull origin main 如果有需要拉取到本地的文件,则将远程分支与当前分支合并
git push -u origin main

在其他机器上使用仓库里的配置文件

git clone git@github.com:username/dotfiles.git --recursive
cd dotfiles && ./install

如果仓库有更新则可通过下面命令更新本地配置:

git pull
./install

总结

通过Dotbot和Git可以方便我们维护dotfiles并通过Git仓库共享配置。

参考

Dotbot – A tool that bootstraps your dotfiles ⚡️

Bootstrap your Dotfiles with dotbot

本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 协议 。转载请注明出处!
您可以通过 RSS 订阅本站文章更新。
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇