4 Applications
约 1186 字大约 4 分钟
2025-04-20
4.1 chezmoi
chezmoi是一个跨多台不同的机器管理 dotfiles 的工具,方便每次在新的电脑/服务器的时候不用麻烦的重新配置一些 config 了
dotfile: 简言之就是应用程式的 config,例如
~/.vimrc
就是dotfile。Linux万物皆文件,Linux 文件名以点开头就会变成隐藏文件,一般也是配置文件,不让一般使用者看到。
4.1.1 安装
安装带自定义路径中:
sh -c "$(wget -qO- chezmoi.io/getlb)" -- -b $HOME/.local/bin
但是一般由于网络问题连不上,请开启代理,或者配置代理之后使用 proxy
命令:
sh -c "$(proxy wget -qO- chezmoi.io/getlb)" -- -b $HOME/.local/bin
由于是自定义安装路径在 $HOME/.local/bin
,所以在 .bashrc
或者 .zshrc
中加入PATH:
# echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
# source ~/.bashrc
source ~/.zshrc
4.1.2 使用
初始化 chezmoi
chezmoi init
这会在
~/.local/share/chezmoi
中创建一个新的 Git 本地仓库,chezmoi
将在此存储其源状态。添加要管理的第一个文件:如将
~/.bashrc
文件交给 chezmoi 管理chezmoi add ~/.bashrc
~/.bashrc
会被复制到~/.local/share/chezmoi/dot_bashrc
。查看和应用更改
查看 chezmoi 将对文件系统做出的更改:
chezmoi diff
然后应用更改到文件系统:
chezmoi -v apply
提交更改到 Git:进入 chezmoi 的源目录使用 Git 提交更改
chezmoi cd git add . git commit -m "Initial commit"
推送到 GitHub:先创建一个名为
dotfiles
的 GitHub 仓库,然后运行以下命令,将 dotfiles 推送到远程仓库:git remote add origin git@github.com:$GITHUB_USERNAME/dotfiles.git git branch -M main git push -u origin main
4.1.3 设置新机器
直接通过一行命令即可将在 Github 上的已有的 dotfile 存储库配置到这台新机器上:
chezmoi init --apply https://github.com/$GITHUB_USERNAME/dotfiles.git
4.2 Git
4.2.1 Fork 成一个私有仓库
本地 git clone 之后,Remove Remote
然后再发布 Branch
选择 Private 的就好了
4.3 rsync
rsync
是一个用于在本地或远程系统之间同步文件和目录的强大工具。它支持增量传输,只传输发生变化的部分,从而提高了效率。以下是 rsync
的基本使用方法和一些常用用法。
基本语法
rsync [选项] 源 目标
常用选项
-a
:归档模式,保留文件属性(如权限、时间戳等),相当于-rlptgoD
。-v
:详细模式,显示传输过程中的详细信息。-z
:压缩传输,减少数据传输量。-P
:显示传输进度,并支持断点续传。-r
:递归复制目录及其内容。-e
:指定远程 shell 程序(如ssh
)。--delete
:删除目标目录中源目录不存在的文件。--exclude
:排除指定文件或目录。--include
:包含指定文件或目录。--dry-run
:模拟运行,不实际执行任何操作。
常用用法
我一般使用的用法:rsync -avP source_dir/ destination_dir/
本地同步 同步本地目录
source_dir
到destination_dir
:rsync -av source_dir/ destination_dir/
远程同步 将本地目录压缩同步到远程服务器:
rsync -avz -e ssh source_dir/ user@remote_host:/path/to/destination_dir/
从远程服务器压缩同步到本地:
rsync -avz -e ssh user@remote_host:/path/to/source_dir/ destination_dir/
删除目标目录中源目录不存在的文件
rsync -av --delete source_dir/ destination_dir/
排除特定文件或目录 排除
source_dir
中的exclude_dir
和exclude_file
:rsync -av --exclude 'exclude_dir' --exclude 'exclude_file' source_dir/ destination_dir/
显示传输进度
rsync -avP source_dir/ destination_dir/
模拟运行 模拟同步操作,不实际执行:
rsync -av --dry-run source_dir/ destination_dir/
同步时保留符号链接
rsync -avL source_dir/ destination_dir/
同步时保留硬链接
rsync -avH source_dir/ destination_dir/
示例
同步本地目录并删除目标目录中多余的文件
rsync -av --delete /path/to/source/ /path/to/destination/
同步远程目录并压缩传输
rsync -avz -e ssh user@remote_host:/path/to/source/ /path/to/destination/
同步时排除特定文件
rsync -av --exclude '*.log' /path/to/source/ /path/to/destination/
注意事项
rsync
的源目录如果以/
结尾,表示同步目录内容;如果不以/
结尾,表示同步目录本身。
4.4 VSCode
4.4.1 Debug 进入第三方文件
launch.json 加入 "justMyCode": false,
,例如:
{
"name": "Train",
"type": "debugpy",
"request": "launch",
"program": "tools/train.py",
"console": "integratedTerminal",
"args": [
// python tools/train.py exp=gvhmr/mixed/mixed
"exp=gvhmr/mixed/full_model/finetune-0.5_0.8-orig_lr-128b"
],
"justMyCode": false,
},
4.4.2 try except 不起作用
因为勾选这个 Raised Exceptions
选项时,就会发生这种情况
4.5 Linux 代理
记得使用 shadowrocket 订阅链接