默认终端 + iTerm2 + oh_my_zsh + agnoster theme + Powerline fonts + solarized 打造macOS炫酷终端

版权声明:本文为博主(SimonLiu)原创文章,未经博主允许不得转载。 https://blog.csdn.net/toopoo/article/details/85301389

先上图

iTerm2效果

macOS自带终端效果

iTerm2

iTerm是一个非常好的终端模拟器,官网地址:http://iterm2.com/ ,下载安装之。

 

oh_my_zsh

查看系统支持的sh环境

cat /etc/shells

macOS已经自带zsh ,但是它不是默认shell

# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.

/bin/bash
/bin/csh
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh

输入如下命令更改zsh为默认shell

chsh -s /bin/zsh

echo $SHELL查看是否切换成功, 返回 /bin/zsh 就对了。

echo $SHELL
/bin/zsh

输入如下命令安装oh_my_zsh

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

 

Solarized配色方案

因为下面的字体需要在新的配色主题中更改,所以需要先安装Solarized配色方案。

git clone https://github.com/altercation/solarized

iTerm2的设置:

进入目录solarized/iterm2-colors-solarized,双击Solarized Dark.itermcolors、Solarized Light.itermcolors导入主题(可能会提示安全性问题,进入系统偏好设置-安全性与隐私-通用 里面确认安装);

iTerm2设置->Profiles->Colors->Color Presets…,在下拉菜单中选择Solarized Dark

macOS自带终端设置:

进入目录solarized/osx-terminal.app-colors-solarized/xterm-256color , 双击运行 Solarized Dark xterm-256color.terminal 和 Solarized Light xterm-256color.terminal 进行安装(可能会提示安全性问题,进入系统偏好设置-安全性与隐私-通用 里面确认安装)。

然后打开 终端 - 偏好设置 - 描述文件,双击 Solarized Dark xterm-256color ,并且点击右下方的“默认”,设置它为默认配色方案。

注意:我这里默认情况下字符背景不好看(上面的图是我修改过的),需要更改如下图中的两个颜色,点击它使用吸管工具,拾取iTerm2的相应位置颜色即可。

Powerline字体

为了显示agnoster主题提示符里的三角形,需要Powerline字体库的支持。使用pip安装

pip install powerline-status

如果没有安装pip,那么先安装pip

sudo easy_install pip

找个位置新建一个font文件夹

mkdir powerlinefonts
cd powerlinefonts

下载字体并运行install.sh安装

git clone https://github.com/powerline/fonts
cd fonts
./install.sh

设置iTerm2字体

进入 iTerm2 - preferences - Profiles -Text - Font,选择其中一种Powerline字体,例如 18pt Meslo LG S DZ Regular for Powerline

设置自带终端字体:

进入 终端 - 偏好设置 - 描述文件 - 文本,选择一个Powerline字体,同上。

agnoster主题 

git clone 下载并安装

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

编辑~/.zshrc ,注释掉Zsh_THEME="robbyrussell",添加一行ZSH_THEME="agnoster", 注意 “ZSH_THEME”需要全部大写,虽然原先默认的那一行是Zsh。这个坑浪费了我一个小时。

#Zsh_THEME="robbyrussell"
ZSH_THEME="agnoster"

 

增加指令高亮效果 zsh-syntax-highlighting 

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

编辑~/.zshrc ,添加

source ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
plugins=(zsh-syntax-highlighting)

 

缩短前缀

 每行前面的xxx@xxxxx太长,只需要编辑~/.zshrc,添加如下一行即可(记住 DEFAULT_USER 全大写),如此设置就取消前缀。

DEFAULT_USER="$USER"

如果你想仅显示当前用户名,可以这样设置:

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

最后使zshrc的profile生效:

source ~/.zshrc

其他相关技巧

  1. 如果想切换回原来的bash:chsh -s /bin/bash

  2. 更新oh_my_zsh,在命令行输入如下命令:upgrade_oh_my_zsh

  3. 卸载oh_my_zsh,在命令行输入如下命令:uninstall_oh_my_zsh

  4. 执行指令pip install powerline-status出错解决方法:需要下载苹果官方的command line tools。

猜你喜欢

转载自blog.csdn.net/toopoo/article/details/85301389