天天看点

iTerm2 + oh-my-zsh + agnoster

开发中终端命令会经常使用到。下面看一下将要修改的效果:

iTerm2 + oh-my-zsh + agnoster

Mac

自带有终端命令框,但功能单一,通常会使用

iTerm2

1、下载iTerm2

官网下载:https://www.iterm2.com

下载完成直接将

iTerm

拖入到应用程序,每次使用直接在应用中点击打开。

iTerm2 + oh-my-zsh + agnoster

Mac

系统默认

shell

类型为

bash

类型,而

iTerm2

则对应

zsh

类型。通过

cat

命令查看有哪些

shell

cat /etc/shells
           

/bin/bash

/bin/csh

/bin/ksh

/bin/sh

/bin/tcsh

/bin/zsh

切换

shell

chsh -s /bin/zsh
           

2、安装oh-my-zsh

curl安装:

wget安装:

oh-my-zsh

带有各种主题,在

/.oh-my-zsh/themes

中:

iTerm2 + oh-my-zsh + agnoster

3、设置主题为agnoster

编辑zsh配置文件:

vim ~/.zshrc
           

修改

ZSH_THEME

字段:

并在最后一行引入

bash

对应的配置文件,使得同时有效:

source ~/.bash_profile
           

4、配置颜色

cmd+点击

(偏好设置) -> Profiles -> Default -> Colors -> Colors Presets

iTerm2 + oh-my-zsh + agnoster

设置后效果如下:

iTerm2 + oh-my-zsh + agnoster

此处有两个问题,一个是命令行前名称过长,占地太多,另一个是问号,字体原因导致。

5、设置命令行前名称

编辑

agnoster.zsh-theme

主题文件

vim ~/.oh-my-zsh/themes/agnoster.zsh-theme
           

修改

prompt_context()

函数中的

black default

参数如下:

prompt_context() {
  if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
    #prompt_segment black default "%(!.%{%F{yellow}%}.)%n@%m"
     prompt_segment black default "HB"
  fi
}
           

此处即是命令行前显示的名称,修改后执行

source ~/.zshrc

命令使配置生效。效果如下:

iTerm2 + oh-my-zsh + agnoster

6、安装字体,去除问号

直接下载字体:https://github.com/powerline/fonts

下载至本地,执行脚本安装:

./install.sh
           

卸载:

./uninstall.sh
           

会加入到

/Users/yanghaibo/Library/Fonts

路径下,原有安装包删除即可。安装字体为

Meslo LG L DZ for Powerline

L M S

分别制定字体为

大 中 小

打开偏好设置设置字体:

iTerm2 + oh-my-zsh + agnoster

重新打开终端即完成了设置:

iTerm2 + oh-my-zsh + agnoster

7、去掉文件路径显示

文件路径较长影响查看和操作,可以修改配置去除路径显示,只显示当前文件名称,如果需要查看路径信息使用命令

pwd

即可。具体设置如下:

编辑

agnoster.zsh-theme

文件,将

prompt_segment blue $CURRENT_FG '%~'

修改为

prompt_segment blue $CURRENT_FG '%1d'

vim ~/.oh-my-zsh/themes/agnoster.zsh-theme

# Dir: current working directory
prompt_dir() {
  #prompt_segment blue $CURRENT_FG '%~'
  prompt_segment blue $CURRENT_FG '%1d'
}
           

修改完成后重启

ssh

配置环境

source ~/.zshrc

,效果如下:

iTerm2 + oh-my-zsh + agnoster

8、安装命令提示插件

下载插件:https://github.com/zsh-users/zsh-autosuggestions

将插件下载至

.oh-my-zsh/custom/plugins/

目录下

cd ~/.oh-my-zsh/custom/plugins/
git clone [https://github.com/zsh-users/zsh-autosuggestions.git](https://github.com/zsh-users/zsh-autosuggestions.git)
           

编辑配置文件:

vi ~/.zshrc
           

添加插件:

plugins=(
   git
   zsh-autosuggestions
)
           

执行命令生效:

source ~/.zshrc
           

如下提示就出现了:

iTerm2 + oh-my-zsh + agnoster

有提示,好像提示文本颜色和背景色相同,我们可以在

zsh-autosuggestions.zsh

中设置:

修改前景色fg为10即可:

修改后重新打开,或重新开启新窗口

cmd+t

,效果如下:

iTerm2 + oh-my-zsh + agnoster

这样看着就舒服多了,用起来

继续阅读