#dotfiles #yaml #config-file #dot #path #across #machines

bin+lib dotfiles-rs

跨机器同步 dot 文件(即配置文件)的简单管理器

5 个版本

0.2.0 2023年11月13日
0.1.3 2023年6月27日
0.1.2 2023年3月26日
0.1.1 2023年3月26日
0.1.0 2022年11月15日

#344 in Cargo 插件

40 每月下载量

Apache-2.0

24KB
310

dotfiles-rs

CI crate

这是一个简单的 dot 文件管理器,用于跨机器同步 dot 文件。

安装

$ git clone https://github.com/wckdouglas/dotfiles-rs.git
$ cd dotfiles-rs
$ cargo install --path .

用法

要管理的 dot 文件(即配置文件)定义在 yaml 文件中(例如 data/dotfiles.yaml)。

保存当前设置

我们可以使用 save 子命令

$ cd dotfiles-rs
$ dotfiles-rs --dotfile-yaml data/dotfiles.yaml save --dest-dir ../dotfiles --dry-run
[2023-03-26T14:46:43Z INFO  dotfiles_rs] [Dry run] Copied /Users/wckdouglas/.zshrc to ../dotfiles/.zshrc
[2023-03-26T14:46:43Z INFO  dotfiles_rs] [Dry run] Copied /Users/wckdouglas/.wezterm.lua to ../dotfiles/.wezterm.lua
[2023-03-26T14:46:43Z INFO  dotfiles_rs] [Dry run] Copied /Users/wckdouglas/.config/nvim/init.lua to ../dotfiles/.config/nvim/init.lua
[2023-03-26T14:46:43Z INFO  dotfiles_rs] [Dry run] Copied /Users/wckdouglas/.gitconfig to ../dotfiles/.gitconfig
[2023-03-26T14:46:43Z INFO  dotfiles_rs] [Dry run] Copied /Users/wckdouglas/.vimrc to ../dotfiles/.vimrc
[2023-03-26T14:46:43Z INFO  dotfiles_rs] [Dry run] Copied /Users/wckdouglas/.ssh/config to ../dotfiles/.ssh/config
[2023-03-26T14:46:43Z INFO  dotfiles_rs] [Dry run] Copied /Users/wckdouglas/.gitignore_global to ../dotfiles/.gitignore_global
[2023-03-26T14:46:43Z INFO  dotfiles_rs] [Dry run] Copied /Users/wckdouglas/.config/alacritty/alacritty.yml to ../dotfiles/.config/alacritty/alacritty.yml
[2023-03-26T14:46:43Z INFO  dotfiles_rs] [Dry run] Copied /Users/wckdouglas/.config/zellij/config.kdl to ../dotfiles/.config/zellij/config.kdl
[2023-03-26T14:46:43Z INFO  dotfiles_rs] You can now go to ../dotfiles and create a github repo!

这将创建一个新的文件夹 ../dotfiles,它可以由 git 进行版本控制

$ tree -a -L 2 ../dotfiles
../dotfiles
├── .config
├── .config
   ├── alacritty
   │   └── alacritty.yml
   ├── nvim
   │   └── init.lua
   └── zellij
       └── config.kdl
├── .gitconfig
├── .gitignore_global
├── .ssh
   └── config
├── .vimrc
├── .zshrc
└── README.md

创建 GitHub 仓库

$ cd ../dotfiles
$ git init -b main
$ git add *
$ git commit -am "Adding dot files"
$ git remote add origin <REMOTE_URL>
$ git push -u origin main

在新机器上应用设置

您将需要提供您从 save 步骤创建的 dotfiles 仓库的 URL(例如 https://github.com/wckdouglas/dotfiles

$ cd dotfiles-rs
$ dotfiles-rs --dotfile-yaml data/dotfiles.yaml apply --url [email protected]:wckdouglas/dotfiles  --ssh-key ~/.ssh/id_ecdsa --dry-run
[2023-03-26T14:51:43Z INFO  dotfiles_rs] Cloning [email protected]:wckdouglas/dotfiles into /Users/wckdouglas/dotfiles
[2023-03-26T14:51:43Z INFO  dotfiles_rs] Clone complete
[2023-03-26T14:51:43Z INFO  dotfiles_rs] [Dry run] Copied /Users/wckdouglas/dotfiles/.wezterm.lua to /Users/wckdouglas/.wezterm.lua
[2023-03-26T14:51:43Z INFO  dotfiles_rs] [Dry run] Copied /Users/wckdouglas/dotfiles/.vimrc to /Users/wckdouglas/.vimrc
[2023-03-26T14:51:43Z INFO  dotfiles_rs] [Dry run] Copied /Users/wckdouglas/dotfiles/.config/alacritty/alacritty.yml to /Users/wckdouglas/.config/alacritty/alacritty.yml
[2023-03-26T14:51:43Z INFO  dotfiles_rs] [Dry run] Copied /Users/wckdouglas/dotfiles/.config/nvim/init.lua to /Users/wckdouglas/.config/nvim/init.lua
[2023-03-26T14:51:43Z INFO  dotfiles_rs] [Dry run] Copied /Users/wckdouglas/dotfiles/.ssh/config to /Users/wckdouglas/.ssh/config
[2023-03-26T14:51:43Z INFO  dotfiles_rs] [Dry run] Copied /Users/wckdouglas/dotfiles/.gitignore_global to /Users/wckdouglas/.gitignore_global
[2023-03-26T14:51:43Z INFO  dotfiles_rs] [Dry run] Copied /Users/wckdouglas/dotfiles/.zshrc to /Users/wckdouglas/.zshrc
[2023-03-26T14:51:43Z INFO  dotfiles_rs] [Dry run] Copied /Users/wckdouglas/dotfiles/.config/zellij/config.kdl to /Users/wckdouglas/.config/zellij/config.kdl
[2023-03-26T14:51:43Z INFO  dotfiles_rs] [Dry run] Copied /Users/wckdouglas/dotfiles/.gitconfig to /Users/wckdouglas/.gitconfig

⚠️ 如果您看到类似这样的错误,您可能需要先创建一个 ecdsa ssh 密钥 ssh-keygen -t ecdsa -b 521 -C "[email protected]"

ERROR: You're using an RSA key with SHA-1, which is no longer allowed. Please use a newer client or a different key type.

Docker

$ docker pull ghcr.io/wckdouglas/dotfiles-rs:main
$ docker run  ghcr.io/wckdouglas/dotfiles-rs:main

调试

在 m1 mac 上,如果您看到类似这样的错误

$ cargo run --
... skipping some compilation messages ...
 = note: Undefined symbols for architecture arm64:
            "_iconv", referenced from:
                _git_fs_path_iconv in liblibgit2_sys-2da99193d83f7067.rlib(fs_path.o)
               (maybe you meant: _git_fs_path_iconv_clear, _git_fs_path_iconv_init_precompose , _git_fs_path_iconv )
            "_iconv_close", referenced from:
                _git_fs_path_iconv_clear in liblibgit2_sys-2da99193d83f7067.rlib(fs_path.o)
            "_iconv_open", referenced from:
                _git_fs_path_iconv_init_precompose in liblibgit2_sys-2da99193d83f7067.rlib(fs_path.o)
          ld: symbol(s) not found for architecture arm64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

那么,这样做可能有效

$ LIBRARY_PATH=/Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk/usr/include cargo install --path .

依赖关系

~15–25MB
~452K SLoC