zsh安装教程

Ubuntu

查看可用shell

cat /etc/shells

安装zsh

sudo apt-get install -y zsh

切换到zsh

chsh -s /bin/zsh

默认终端启动zsh需要在终端中进行配置:

  • 打开终端,编辑>>>>首选项>>>>命令
  • 勾选“运行自定义命令而不是shell” 选项
  • 在下面的“自定义命令”中填写 "zsh"

使用ohmyzsh配置zsh

下载 ohmyzsh 的 zip压缩包. https://github.com/ohmyzsh/ohmyzsh
解压后重命名文件夹为~/.oh-my-zsh:

mv ohmyzsh-master ~/.oh-my-zsh

创建zsh配置文件:

cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

Mac

因排版和原文中的一些bug,参照搜索引擎和原文有了本篇文章。需要注意的是,如果您经常有使用command +来放大字体,那么这个主题可能会产生样式上兼容性的问题。可以只安装oh my zsh,后面的步骤都忽略掉(当然也没有这样的样式了)。

安装iTerm2

官网地址:
https://www.iterm2.com/

切换bash为zsh:

chsh -s /bin/zsh

如果想切回原bash,可以:

chsh -s /bin/bash

安装Oh-my-zsh

两种安装方式:

## wget 安装方式
sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
## curl 安装方式
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

如果网络不好,会出现 拒绝链接 的字样,多试几次就好了。

oh-my-zsh开源地址:https://github.com/robbyrussell/oh-my-zsh

安装PowerLine

先安装pip

sudo easy_install pip

再安装PowerLine

pip install powerline-status --user

安装PowerFonts

madir ~/Desktop/OpenSource
cd ~/Desktop/OpenSource
git clone https://github.com/powerline/fonts.git --depth=1
cd fonts
./install.sh

安装好字体库之后,我们来设置iTerm2的字体,具体的操作是iTerm2 -> Preferences -> Profiles -> Text,在Font区域选中Change Font,然后找到Meslo LG字体。有L、M、S可选,看个人喜好:

安装配色方案

配色方案在使用VIM或Colorful Log时会变得非常有用,同时界面也不会一片黑绿一样死板。
同样使用git clone的方式下载源码进行安装:

cd ~/Desktop/OpenSource
git clone https://github.com/altercation/solarized
cd solarized/iterm2-colors-solarized/
open .

在打开的finder窗口中,双击Solarized Dark.itermcolors和Solarized Light.itermcolors即可安装明暗两种配色:
再次进入iTerm2 -> Preferences -> Profiles -> Colors -> Color Presets中根据个人喜好选择这两种配色中的一种即可:

安装主题

下载agnoster主题,执行脚本安装

cd ~/Desktop/Opeurce
git clone https://github.com/fcamblor/oh-my-zsh-agnoster-fcamblor.git
cd oh-my-zsh-agnoster-fcamblor/
./install

拷贝完成后,执行命令打开zshrc配置文件,将ZSH_THEME后面的字段改为agnoster。

vi ~/.zshrc

修改完成后按一下esc调出vi命令,输入:wq保存并退出vi模式。

此时command+Q或source配置文件后,iTerm2变了模样.

安装高亮插件

这是oh my zsh的一个插件,安装方式与theme大同小异:

cd ~/.oh-my-zsh/custom/plugins/
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git
vi ~/.zshrc

这时我们再次打开zshrc文件进行编辑。找到plugins,此时plugins中应该已经有了git,我们需要把高亮插件也加上.
请务必保证插件顺序,zsh-syntax-highlighting必须在最后一个。

然后在文件的最后一行添加:source ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

按一下esc调出vi命令,输入:wq保存并退出vi模式。

执行命令使刚才的修改生效:

source ~/.zshrc

至此大功告成.

更换背景图片方式:iTerm2 -> Preferences -> Profiles -> Window -> BackGround Image勾选图片即可。

命令补全插件

跟代码高亮的安装方式一样,这也是一个zsh的插件,叫做zsh-autosuggestion,用于命令建议和补全。

cd ~/.oh-my-zsh/custom/plugins/
git clone https://github.com/zsh-users/zsh-autosuggestions
vi ~/.zshrc

找到plugins,加上这个插件即可.
有同学说补全命令的字体不太清晰,与背景颜色太过相近,其实可以自己调整一下字体颜色。

Preferences -> Profiles -> Colors -> Foreground->(156,207,213)
(156,207,213)

调整窗口大小

调整新建终端的窗口大小:
Preferences -> Profiles -> Window -> Setting for new windows -> (120,35)

参考链接:
https://github.com/ohmyzsh/ohmyzsh
https://www.jianshu.com/p/9c3439cc3bdb

posted @ 2020-05-10 01:07  多弗朗强哥  阅读(648)  评论(0编辑  收藏  举报