美文网首页
iTerm2 + Oh My Zsh 打造极致舒适终端环境

iTerm2 + Oh My Zsh 打造极致舒适终端环境

作者: 小奉不在乎 | 来源:发表于2023-04-22 17:19 被阅读0次

    先看下最终效果图:


    image.png

    1. 下载iTerm2

    可以直接去官网下载:https://www.iterm2.com/

    安装完成后,在/bin目录下会多出一个zsh的文件。

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

    chsh -s /bin/zsh
    

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

    chsh -s /bin/bash
    

    OK,这就是iTerm2初始的样子,下面我们来美化它,让它变得更好用!


    image.png

    2. 安装Oh my zsh

    安装方法有两种,可以使用curl或wget,看自己环境或喜好:

    # curl 安装方式
    sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
    
    # wget 安装方式
    sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
    

    安装命令和安装完成后的截图:

    image.png
    oh-my-zsh开源地址:https://github.com/ohmyzsh/ohmyzsh

    3. 安装PowerLine

    powerline官网:https://powerline.readthedocs.io/en/latest/installation.html

    安装powerline的方式依然简单,也只需要一条命令:

    pip3 install powerline-status --user
    

    4. 安装PowerFonts

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

    在你习惯的位置新建一个文件夹,如:~/Desktop/OpenSource/

    # git clone
    git clone https://github.com/powerline/fonts.git --depth=1
    # cd to folder
    cd fonts
    # run install shell
    ./install.sh
    
    image.png

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

    image.png
    image.png

    5. 安装配色方案

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

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

    cd ~/Desktop/OpenSource
    git clone https://github.com/altercation/solarized
    cd solarized/iterm2-colors-solarized/
    open .
    

    在打开的finder窗口中,双击Solarized Dark.itermcolors和Solarized Light.itermcolors即可安装明暗两种配色:


    image.png

    再次进入iTerm2 -> Settings -> Profiles -> Colors -> Color Presets中根据个人喜好选择这两种配色中的一种即可:


    image.png

    6.安装主题

    下载agnoster主题,执行脚本安装:

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

    执行上面的命令会将主题拷贝到oh my zsh的themes中:


    image.png

    拷贝完成后,执行命令打开zshrc配置文件,将ZSH_THEME后面的字段改为agnoster。

    vi ~/.zshrc
    
    image.png

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

    此时command+Q或source配置文件后,iTerm2变了模样:


    image.png

    6.安装命令补全/高亮插件

    这是oh my zsh的一个插件,安装方式与theme大同小异:

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

    这时我们再次打开zshrc文件进行编辑。找到plugins,此时plugins中应该已经有了git,zsh-autosuggestions,zsh-syntax-highlighting


    image.png

    请务必保证插件顺序,zsh-syntax-highlighting必须在最后一个。
    然后在文件的最后一行添加:source ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

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

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

    source ~/.zshrc
    

    至此大功告成

    image.png image.png

    更换背景图片方式:iTerm2 -> Settings -> Profiles -> Window -> BackGround Image勾选图片即可。

    本文抄袭原文:https://segmentfault.com/a/1190000014992947

    相关文章

      网友评论

          本文标题:iTerm2 + Oh My Zsh 打造极致舒适终端环境

          本文链接:https://www.haomeiwen.com/subject/ldmsjdtx.html