Code Monkey home page Code Monkey logo

prezto's Introduction

Prezto — 又快又好的 Zsh

在经历了 Zinit 和 Zplug 无法正常更新插件的煎熬后, 才能意识到 Prezto 使用纯 git 方式管理插件的好处。

安装

Fork Prezto

https://github.com/sorin-ionescu/prezto 进行 Fork

Clone 到本地

记得把以下命令中的 aQuaYi 替换成你自己的ID

$ zsh
$ git clone --recursive --shallow-submodules https://github.com/aQuaYi/prezto.git "${ZDOTDIR:-$HOME}/.zprezto"
$

生成 Zsh 配置文件的软连接

在 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 进行管理。

把 Zsh 设置成默认 Shell

$ which zsh
/usr/bin/zsh
$ chsh -s /usr/bin/zsh
$

保存自己的配置

  1. 删除了 .gitignore 中的 contrib
  2. 修改项目的 README.mdREADME-EN.md
  3. 添加此 README.md 文件到项目根目录。
  4. git addcommit & 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
$

现在可以像自带插件一样启用了。

添加 prezto-contrib 模块库

https://github.com/belak/prezto-contrib 也收集了一些兼容 Prezto 的插件。 按照其 README 安装后,可以很方便地添加插件。 但是由于 contrib 也包含在 .gitignore 文件中,无法以子模块的方式更新。

本人使用以下方式安装 prezto-contrib 模块库。

  1. 删除了 .gitignore 中的 contrib

  2. prezto-contrib 作为子模块拷贝到 $ZPREZTODIR

$ cd $ZPREZTODIR
$ git submodule add https://github.com/belak/prezto-contrib.git contrib
$ git submodule update --init --recursive
$

从 sorin-ionescu/prezto 同步

按照以上方法安装 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)

抓取 sorin 的内容

$ git fetch sorin
$

合并到 master 分支

$ git checkout master && git merge sorin/master
$

遭遇冲突,可用 git status 查看冲突内容

只有 README 的冲突是以本文件为准。其余的冲突一律以 sorin 的为准。

可以在运行了 git status 后,使用 git add <文件名> 来解决。

推送更新内容到 origin

$ 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 中的 uzauzc 命令。

runcoms 中修改环境变量

Go 和 Rust 的环境变量设置, 均在 /runcoms/zshenv 文件中。

Zsh

.git/config 无法使用 github 同步的问题

由于 .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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.