csjiabin's blog csjiabin's blog
首页
  • 学习笔记

    • 《JavaScript教程》
    • 《JavaScript高级程序设计》
    • 《ES6 教程》
    • 《Vue》
    • 《React》
    • 《TypeScript 从零实现 axios》
  • 学习笔记

    • 《面向Node.js开发者的Go》
更多
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

csjiabin

前端界的小菜鸟
首页
  • 学习笔记

    • 《JavaScript教程》
    • 《JavaScript高级程序设计》
    • 《ES6 教程》
    • 《Vue》
    • 《React》
    • 《TypeScript 从零实现 axios》
  • 学习笔记

    • 《面向Node.js开发者的Go》
更多
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • 《Git》学习笔记
  • Markdown使用指南
  • Mathjax与KaTex渲染数学公式
  • iTerm2 + Oh My Zsh 打造舒适终端体验
    • linux下tar.gz、tar、bz2、zip等解压缩、压缩命令小结
    • Nginx负载均衡配置与负载策略
    • DayDart 具备 Day.js 一样API的时间处理库.
    • VS Code的使用
    • 咖啡知识
    • 更多
    csjiabin
    2020-07-24
    目录

    iTerm2 + Oh My Zsh 打造舒适终端体验

    # 效果预览

    效果图 本文以Mac为例,因为 powerline 以及 homebrew 均需要安装 command line tool,网络条件优越的同学在执行本文下面内容之前,可以先安装 XCode 并打开运行一次(会初始化安装 components),省去以后在 iterm2 中的等待时间。

    另外,git 也是必要的,各位可以自行下载安装,除了网络没有任何坑:https://git-scm.com

    # 下载安装 iTerm2

    下载地址:https://www.iterm2.com/downloads.html

    下载的是压缩文件,解压后是执行程序文件,你可以直接双击,或者直接将它拖到 Applications 目录下。

    或者你可以直接使用 Homebrew 进行安装:

    brew cask install iterm2
    
    1

    # 安装 Oh my zsh

    Oh my zsh 开源地址:https://github.com/ohmyzsh/ohmyzsh 安装方法有两种,可以使用 curl 或 wget,看自己环境或喜好:

    # curl 安装方式
    sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
    
    1
    2
    # wget 安装方式
    sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
    
    1
    2

    安装 oh my zsh 失败:curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused 解决方案参考地址:https://blog.csdn.net/huangpin815/article/details/105606135

    # 安装 PowerLine

    Powerline 是 agnoster 主题的依赖。具体可以在 repo 里查询到:https://github.com/agnoster/agnoster-zsh-theme powerline 官网:https://powerline.readthedocs.io/en/latest/installation.html 安装 powerline 的方式依然简单,也只需要一条命令:

    pip install powerline-status --user
    
    1

    没有安装 pip 的同学可能会碰到 zsh: command not found: pip,则先执行安装 pip 指令。

    sudo easy_install pip
    
    1

    # 下载、安装库字体库

    安装字体库 (opens new window)需要首先将项目 git clone 至本地,然后执行源码中的 install.sh。

    git clone https://github.com/powerline/fonts.git --depth=1
    
    cd fonts
    
    ./install.sh
    
    1
    2
    3
    4
    5

    安装完成后提示所有字体均已下载到/Users/xxx/Library/Fonts 路径下

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

    设置iTerm 2

    # 安装配色方案

    配色方案在使用 VIM 或 Colorful Log 时会变得非常有用,同时界面也不会一片黑绿一样死板。

    同样使用 git clone 的方式下载源码进行安装:

    git clone git://github.com/altercation/solarized.git
    
    cd solarized/iterm2-colors-solarized
    
    open .
    
    1
    2
    3
    4
    5

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

    # 安装主题

    1. 下载 agnoster 主题,执行脚本安装:
    git clone https://github.com/fcamblor/oh-my-zsh-agnoster-fcamblor.git
    
    cd oh-my-zsh-agnoster-fcamblor
    
    ./install
    
    1
    2
    3
    4
    5

    到下载的工程里面运行 install 文件,主题将安装到~/.oh-my-zsh/themes 目录下

    1. 设置该主题
    vi ~/.zshrc
    
    1

    进入~/.zshrc编辑.zshrc文件,然后将ZSH_THEME后面的字段改为agnoster。ZSH_THEME="agnoster"(agnoster 即为要设置的主题)执行

    # 增加指令高亮效果

    指令高亮效果作用是当用户输入正确命令时指令会绿色高亮,错误时命令红色高亮. 这是 oh my zsh 的一个插件,安装方式与 theme 大同小异:

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

    这时我们再次打开 zshrc 文件进行编辑。找到 plugins,此时 plugins 中应该已经有了 git,我们需要把高亮插件也加上: plugins

    请务必保证插件顺序,zsh-syntax-highlighting 必须在最后一个。

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

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

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

    source ~/.zshrc
    
    1

    # 可选择、命令补全

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

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

    找到 plugins,加上这个插件即可: plugins 插件效果 如果感觉补全命令的字体不太清晰,与背景颜色太过相近,其实可以自己调整一下字体颜色。

    Preferences -> Profiles -> Colors 中有 Foreground 是标准字体颜色,ANSI Colors 中 Bright 的第一个是补全的字体颜色。

    # 结论

    Mac 系统默认使用 dash 作为终端,可以使用命令修改默认使用 zsh:

    chsh -s /bin/zsh
    
    1

    如果想修改回默认 dash,同样使用 chsh 命令即可:

    chsh -s /bin/bash
    
    1

    如果找不到.zshrc 文件问题,可以自己手动创建.zshrc

    卸载oh my zsh,在命令行输入如下命令,回车即可:uninstall_oh_my_zsh

    编辑 (opens new window)
    #git#iTerm2#zsh#pip#powerline
    上次更新: 2022/09/30, 11:34:22
    Mathjax与KaTex渲染数学公式
    linux下tar.gz、tar、bz2、zip等解压缩、压缩命令小结

    ← Mathjax与KaTex渲染数学公式 linux下tar.gz、tar、bz2、zip等解压缩、压缩命令小结→

    最近更新
    01
    咖啡知识
    10-13
    02
    documentation
    09-29
    03
    benchmarking
    09-29
    更多文章>
    Theme by Vdoing | Copyright © 2018-2022 csjiabin | MIT License
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式