zsh

使用iterm2加上oh-my-zsh加载过多插件,存在性能问题。
感觉个人使用的需求其实就是让终端文字高亮即可,所以不需要加载那么多花哨的东西,终端就用mac自带的就可以了。

切换shell为zsh

如果是新版本的mac os默认都是zsh

安装oh-my-zsh

gitee上有该项目的镜像,安装速度更快
https://gitee.com/mirrors/oh-my-zsh
sh -c "$(curl -fsSL wget https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh)"

config

~/.zshrc文件只剩下这些即可

以下可选:

#禁用自动更新
DISABLE_AUTO_UPDATE=true
DISABLE_UPDATE_PROMPT=true

上述两条设置经常失败,可以手动修改脚本,把这一行注释即可:

$ grep -riIn 'check_for_upgrade.sh'
oh-my-zsh.sh:60:#source "$ZSH/tools/check_for_upgrade.sh"

效果

ys主题的修改

默认ys主题冗余信息太多,我删掉了一部分

kun in ~/.oh-my-zsh/themes git:master x > git diff
diff --git a/themes/ys.zsh-theme b/themes/ys.zsh-theme
index 4c3c56f..088552d 100644
--- a/themes/ys.zsh-theme
+++ b/themes/ys.zsh-theme
@@ -6,7 +6,7 @@
 # Mar 2013 Yad Smood
 
 # VCS
-YS_VCS_PROMPT_PREFIX1=" %{$reset_color%}on%{$fg[blue]%} "
+YS_VCS_PROMPT_PREFIX1="%{$reset_color%}%{$fg[blue]%} "
 YS_VCS_PROMPT_PREFIX2=":%{$fg[cyan]%}"
 YS_VCS_PROMPT_SUFFIX="%{$reset_color%}"
 YS_VCS_PROMPT_DIRTY=" %{$fg[red]%}x"
@@ -65,10 +65,7 @@ local exit_code="%(?,,C:%{$fg[red]%}%?%{$reset_color%})"
 # % ys @ ys-mbp in ~/.oh-my-zsh on git:master x [21:47:42] C:0
 # $
 PROMPT="
-%{$terminfo[bold]$fg[blue]%}#%{$reset_color%} \
 %(#,%{$bg[yellow]%}%{$fg[black]%}%n%{$reset_color%},%{$fg[cyan]%}%n) \
-%{$reset_color%}@ \
-%{$fg[green]%}%m \
 %{$reset_color%}in \
 %{$terminfo[bold]$fg[yellow]%}%~%{$reset_color%}\
 ${hg_info}\
@@ -76,5 +73,4 @@ ${git_info}\
 ${svn_info}\
 ${venv_info}\
  \
-[%*] $exit_code
-%{$terminfo[bold]$fg[red]%}$ %{$reset_color%}"
+%{$terminfo[bold]%}> %{$reset_color%}"

zsh 与find 不兼容的问题

no matches found: *.h错误
因为zsh缺省情况下始终自己解释这个 *.h,而不会传递给 find 来解释。
解决办法:
~/.zshrc中加入:
setopt no_nomatch, 然后进行source ~/.zshrc命令

zsh环境变量

在使用bash的时候,环境变量加载顺序是这样的

a. /etc/profile
b. /etc/paths
c. ~/.bash_profile
d. ~/.bash_login
e. ~/.profile
f. ~/.bashrc

前两个是系统级的,切换到zsh之后是不变的。
后边几个则全部改变了(上边的都是bash的),

a. /etc/profile
b. /etc/paths
c. /etc/zprofile
d. /etc/zshrc
e. ~/.zprofile
f. ~/.zshrc

关于.zprofile.pysave
安装python时,一些安装程序将修改您的.bash_profile。它们将您以前的版本保存在.bash_profile.pysave

-------------以下为之前的-------------------

转自:https://www.cnblogs.com/toulanboy/p/9609365.html

下载安装iterm2

官网:https://www.iterm2.com
在官网下载安装包,将安装包移到应用程序,然后打开就可以使用。
安装完毕后,后面的操作都用这个终端来操作。这样可以看到直观效果。

切换shell为zsh

chsh -s /bin/zsh

重新打开iterm2,并查看是否切换成功

echo $SHELL

安装oh-my-zsh

sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

安装额外的字体库

(某些主题会用到一些其他字体) 
Powerline字体: https://github.com/powerline/fonts

安装步骤如下(来自其github):

# clone
git clone https://github.com/powerline/fonts.git --depth=1
# install
cd fonts
./install.sh
# clean-up a bit
cd ..
rm -rf fonts

安装好之后,选择一款Powerline字体了:iterm2 -> Preferences -> Profiles -> Text -> Font -> Change Font(我用的是Meslo LG)

修改主题配置

首先打开家目录下的.zshrc文件,然后修改下面指定行便是配置主题的

Copy首先打开家目录下的.zshrc文件,然后修改下面指定行便是配置主题的

ZSH_THEME="agnoster"

这个可以设置终端主题。这个agnoster主题很炫酷,大家可以试一试。

每次修改主题配置,都需要重启terminal终端。

其他主题可以参考Oh My Zsh主题展示网站

DEFAULT_USER=$USER

这个特别喜欢!新增这个配置可以去掉shell每行前面的user@hostname
ZSH_THEME="agnoster"
这个可以设置终端主题。这个agnoster主题很炫酷,大家可以试一试。
每次修改主题配置,都需要重启terminal终端。
其他主题可以参考Oh My Zsh主题展示网站

DEFAULT_USER=$USER

这个特别喜欢!新增这个配置可以去掉shell每行前面的user@hostname

命令高亮(可选)

这个插件可以让ls/vim等命令高丽显示。效果图如下:

zsh-syntax-highlighting地址:https://github.com/zsh-users/zsh-syntax-highlighting

安装步骤如下(来自其github):

 git clone https://github.com/zsh-users/zsh-syntax-highlighting.git
 echo "source ${(q-)PWD}/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc

重启终端,即可启动高亮效果。

再提一点,使用zsh之后,vscode的终端可能乱码,也是字体问题,使用下面的设置方式,把vscode的终端字体设置成iterm一样的即可

posted @ 2020-06-04 16:32  feipeng8848  阅读(409)  评论(0编辑  收藏  举报