在经历了 Zinit 和 Zplug 无法正常更新插件的煎熬后, 才能意识到 Prezto 使用纯 git 方式管理插件的好处。
到 https://github.com/sorin-ionescu/prezto 进行 Fork
记得把以下命令中的
aQuaYi
替换成你自己的ID。
$ zsh
$ git clone --recursive --shallow-submodules https://github.com/aQuaYi/prezto.git "${ZDOTDIR:-$HOME}/.zprezto"
$
在 zsh 中执行以下命令。 如果你已经拥有了 zsh 的相关配置的话, 请备份后,把命令中的
ln
替换成ln -f
$ setopt EXTENDED_GLOB
$ for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do
ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"
done
$
生成符号链接的好处是,配置文件始终在资源库中,可以利用 git 进行管理。
$ which zsh
/usr/bin/zsh
$ chsh -s /usr/bin/zsh
$
- 删除了
.gitignore
中的contrib
- 修改项目的
README.md
为README-EN.md
- 添加此
README.md
文件到项目根目录。 - git
add
,commit
&push
到 github
例如,想要添加 modules
目录中的 git
插件。
只需在 ~/.zpreztorc
文件的
zstyle ':prezto:load' pmodule \
'environment' \
'terminal' \
'editor' \
'history' \
'directory' \
'spectrum' \
'utility' \
'completion' \
'prompt'
中添加一行 'git' \
, 成为
zstyle ':prezto:load' pmodule \
'environment' \
'terminal' \
'editor' \
'history' \
'directory' \
'spectrum' \
'utility' \
'completion' \
'git' \
'prompt'
即可。
想要在 Prezto 中添加 https://github.com/aQuaYi/zsh-alias 插件
$ cd $ZPREZTODIR/modules
$ git submodule add https://github.com/aQuaYi/zsh-alias.git
$
对于不需要自己修改的模块,可以在
$ZPREZTODIR/.gitmodules
文件中的 [submodule "modules/zsh-alias"] 项目下, 添加shallow = true
[submodule "modules/zsh-alias"]
path = modules/zsh-alias
url = https://github.com/aQuaYi/zsh-alias.git
shallow = true
$ git add -A
$ git commit -m "add zsh-alias"
$ git push
$
现在可以像自带插件一样启用了。
https://github.com/belak/prezto-contrib 也收集了一些兼容 Prezto 的插件。
按照其 README 安装后,可以很方便地添加插件。
但是由于 contrib
也包含在 .gitignore
文件中,无法以子模块的方式更新。
本人使用以下方式安装 prezto-contrib 模块库。
-
删除了
.gitignore
中的contrib
-
把
prezto-contrib
作为子模块拷贝到$ZPREZTODIR
$ cd $ZPREZTODIR
$ git submodule add https://github.com/belak/prezto-contrib.git contrib
$ git submodule update --init --recursive
$
按照以上方法安装 Prezto 后,还可以同步其后续的更新。
以下过程从 Github 的官方文档为复刻配置远程仓库和同步复刻总结。
$ git remote -v
origin https://github.com/aQuaYi/prezto.git (fetch)
origin https://github.com/aQuaYi/prezto.git (push)
$ git remote add sorin https://github.com/sorin-ionescu/prezto.git
$ git remote -v
origin https://github.com/aQuaYi/prezto.git (fetch)
origin https://github.com/aQuaYi/prezto.git (push)
sorin https://github.com/sorin-ionescu/prezto.git (fetch)
sorin https://github.com/sorin-ionescu/prezto.git (push)
$ git fetch sorin
$
$ git checkout master && git merge sorin/master
$
遭遇冲突,可用
git status
查看冲突内容
只有 README 的冲突是以本文件为准。其余的冲突一律以 sorin 的为准。
可以在运行了 git status
后,使用 git add <文件名>
来解决。
$ git push origin master
$
$ cd $ZPREZTODIR && \
git submodule update --remote --recursive && \
git add -A -v && \
git commit -m "update submodules" && \
git submodule update -f --init --recursive && \
git push && \
zsh
添加git submodule update -f --init --recursive
的原因在这里
最好可以在 git config 中添加以下内容
$ git config --global diff.ignoreSubmodules dirty
$
还可以参考 aQuaYi/zsh-alias 中的 uza
和 uzc
命令。
Go 和 Rust 的环境变量设置, 均在 /runcoms/zshenv
文件中。
由于 .git 文件夹中包含的内容,不用同步到远程,所以 .git/config 关于 submodule 的路径信息也就丢失了。 需要收到添加在别处添加的 submodule 的路径地址。
我现在想到的解决办法是,
把原版的 config 移动到上级目录的 .git-config,然后生成 .git/config 到 ../.git-config 的符号链接。
~/.zprezto/.git master 22:58:26
❯ mv config ../.git-config
~/.zprezto/.git master ?2 23:00:22
❯ ln -s ../.git-config config
~/.zprezto/.git master !1 ?2 23:08:13
❯ ll config
Permissions Size User Date Modified Git Name
lrwxrwxrwx 14 aqua 04-20 23:00 -N config -> ../.git-config