iTerm2+Oh-My-Zsh 教你如何在MAC上打造自己的终端


标签:工具 主题

1、安装完成之后的样式

iterm2主题配置完成后的样子

2、安装iTerm2

我以前就装过,所以这步骤略过。然后打开iTerm2,后面的操作全都在iterm2中完成。

3、安装oh-my-zsh

安装

curl方式安装
$ curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh

安装失败,转而下载资源到本地进行安装。

下载到本地进行安装
$ cd ~
$ git clone https://github.com/robbyrussell/oh-my-zsh
$ cd ~/Downloads/ohmyzsh-master/tools
$ ./install.sh
  • 安装时遇到的问题:

安装zsh失败信息1

  • 解决方案:

    • 如果Safari地址栏中键入: github.com:443后进入的Github是自己的仓库,那就退出登录。如果出现的是Github的登录界面,那就登录Github。我采用这个方法就解决了上述问题。我猜测是因为我没有给github设置SSH导致的。

    • 终端Clone项目失败就在Safari上刷新GitHub的网页,如果网页能刷新再继续Clone。(WiFi刷新失败可尝试切换热点)

  • 安装成功

    安装成功的截图如下,这里折腾了好久,安装成功给我高兴坏了。

    安装zsh成功1

    安装zsh成功2

4、安装Powerline

powerline的作用

Powerline插件主要解决很多关于 oh my zsh 主题中的字体问题,比如有特殊的表情和符号的主体出现的乱码问题等。

安装pip

安装powerline之前需要安装pip。

方案一
$ sudo easy_install pip
  • 出现错误

    SyntaxError: invalid syntax

换个方法安装。

方案二
$ curl 'https://bootstrap.pypa.io/get-pip.py' > get-pip.py

$ sudo python3 get-pip.py
  • 安装成功

    Successfully installed pip-22.0.4

安装powerline-status

$ pip install powerline-status
  • 安装成功

    Successfully installed powerline-status-2.7

5、安装PowerFonts字体库

下载字体库

$ git clone https://github.com/powerline/fonts

安装字体库

进入fonts目录下,执行查看是否有install.sh文件,如果有按照下面步骤安装Powerline的字体。

$ cd fonts/
$ ./install.sh
  • 提示字体安装成功

Powerline fonts installed to /Users/teresa/Library/Fonts

设置iTerm 2的字体

进入iTerm 2的设置里找到Profile中的Text ,设置Font的字体为Powerline的字体即可。

步骤:iTerm2 -> Preferences -> Profiles -> Text

在iterm2中配置powerline的字体

6、配置配色方案

下载

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

导入iTerm2中

进入刚刚下载的文件的./iterm2-colors-solarized 下双击 Solarized Dark.itermcolorsSolarized Light.itermcolors 把两个配置文件导入到 iTerm2 里。

选择配色方案

进入iTerm 2的设置里找到Profile中的Color ,在color presets中选择Solarized Dark或者Solarized Light都可以。

步骤:iTerm2 -> Preferences -> Profiles -> Tolor

选择配色方案

7、安装主题

下载主题
$ git clone https://github.com/fcamblor/oh-my-zsh-agnoster-fcamblor
安装agnoster主题

运行install文件,主题将被自动安装到~/.oh-my-zsh/themes目录下:

$ cd ~/Downloads/oh-my-zsh-agnoster-fcamblor-master
$ ./install
  • 安装时遇到的问题:

    安装时提示~/.oh-my-zsh/themes/目录不存在,追溯后才发现是第一步zsh的安装就失败了。默默回去解决oh-my-zsh的安装问题,如果地基没打好,后面一定会困囿于各种奇怪的bug中。所以,一定要保证zsh以及它的配置的正确性哦~

  • 配置.zshrc文件

    打开.zshrc文件

    $ vi ~/.zshrc
    

    配置ZSH_THEME=”agnoster“,agnoster就是我们要用的主题。

ZSH_THEME=”agnoster“

安装powerlevel9k主题
  • 下载

    这里我用了github的镜像,不然打不开github。

    $ git clone https://github.com/bhilburn/powerlevel9k.git ~/.oh-my-zsh/themes/powerlevel9k
    
  • 配置.zshrc文件

    ZSH_THEME=”powerlevel9k/powerlevel9k“

安装powerlevel10k主题
  • 下载&安装

    国内直接使用gitee.com的镜像即可。

    Just make sure to disable the current theme in your plugin manager.

    指导手册上要求先废弃当前正在使用的主题,再安装powerlevel10k

    官方安装指导如下:

    git clone --depth=1 https://gitee.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
    

    我依然和前面安装powerlevel9k的方式保持一致:

    git clone --depth=1 https://gitee.com/romkatv/powerlevel10k.git ~/.oh-my-zsh/themes/powerlevel10k
    
  • 配置.zshrc文件

    ZSH_THEME=”powerlevel10k/powerlevel10k“

经过一系列自定义模板的选择后就可以进入iTerm2页面啦,可选择的模板特别多,我自己的定制模板深得我心,嘿嘿!

powerlevel10k主题界面

想了解更多使用方法,欢迎移步powerlevel10k官方。

8、设置高亮插件

下载插件
$ cd ~/.oh-my-zsh/custom/plugins
$ git clone git://github.com/zsh-users/zsh-syntax-highlighting.git
配置.zshrc文件

plugins中配置高亮插件,zsh-syntax-highlighting必须放在末尾。

plugins=(
git
zsh-syntax-highlighting
)

.zshrc文件最后一行增加配置

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

9、配置命令补全

下载插件
$ cd ~/.oh-my-zsh/custom/plugins/

$ git clone https://github.com/zsh-users/zsh-autosuggestions


.zshrc文件中配置命令补全插件

plugins=(
git
zsh-autosuggestions
zsh-syntax-highlighting
)

10、iTerm2-Color-Schemes主题集的运用

iTerm2不仅支持 macOS 原生 Terminal.app,还支持了包括 iTerm2、Konsole、PuTTY、Xresources、Termite、XFCE 和 Terminator 等app的主题。

下载地址

$ git clone https://github.com/mbadolato/iTerm2-Color-Schemes

配色方案

schemes文件夹下面所有配色方案都可以用于iTerm2中

screenshots文件夹中有配色图片

适用于Mac 系统自带的Terminal.app的主题

terminal文件夹下面主题适用于Mac 系统自带的Terminal.app

11、资料参考

本文参考以下众多网友的文章,感谢网友们的分享。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM