zoukankan      html  css  js  c++  java
  • Mac OS 终端 iTerm2配置大全

    转载链接:https://www.cnblogs.com/diyxiaoshitou/p/9017413.html,在按照原文执行时发现有些问题,所以本文对原文中存在问题的地方做了些调整。

    之前一直使用 Mac OS 自带的终端,用起来虽然有些不太方便,但总体来说还是可以接受的,是有想换个终端的想法,然后今天偶然看到一个终端利器 iTerm2,发现真的很强大,也非常的好用,按照网上配置了主题什么的,还是有些坑的,这边再记录下,以便后面查阅。

    1. 安装 iTerm2

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

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

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

    $ brew cask install iterm2

    2. 配置 iTerm2 主题

    iTerm2 最常用的主题是 Solarized Dark theme,下载地址:http://ethanschoonover.com/solarized

    下载的是压缩文件,你先解压一下,然后打开 iTerm2,按Command + ,键,打开 Preferences 配置界面,然后Profiles -> Colors -> Color Presets -> Import

    选择刚才解压的solarized->iterm2-colors-solarized->Solarized Dark.itermcolors文件,导入成功,最后选择 Solarized Dark 主题,就可以了。

    3. 配置 Oh My Zsh

    Oh My Zsh 是对主题的进一步扩展,地址:https://github.com/robbyrussell/oh-my-zsh

    一键安装:

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

    安装好之后,需要把 Zsh 设置为当前用户的默认 Shell(这样新建标签的时候才会使用 Zsh):

    $ chsh -s /bin/zsh

    然后,我们编辑vim ~/.zshrc文件,将主题配置修改为ZSH_THEME="agnoster"

    agnoster是比较常用的 zsh 主题之一,你可以挑选你喜欢的主题,zsh 主题列表:https://github.com/robbyrussell/oh-my-zsh/wiki/themes

    效果如下(配置了声明高亮):

     注意:到这里会发现iTerm2终端上会出现乱码,原因是我们需要Meslo字体支持,执行下面配置Meslo字体步骤即可解决乱码。

    4. 配置 Meslo 字体

    使用上面的主题,需要 Meslo 字体支持,要不然会出现乱码的情况,字体下载地址:[https://github.com/powerline/fonts/blob/master/Meslo%20Slashed/Meslo%20LG%20M%20Regular%20for%20Powerline.ttf]

    下载好之后,直接在 Mac OS 中安装即可。

    然后打开 iTerm2,按Command + ,键,打开 Preferences 配置界面,然后Profiles -> Text -> Font -> Chanage Font,选择 Meslo LG M Regular for Powerline字体。

    当然,如果你觉得默认的12px字体大小不合适,可以自己进行修改。

    5. 声明高亮

    效果就是上面截图的那样,特殊命令和错误命令,会有高亮显示。
    在这个路径下 cd ~/.oh-my-zsh/custom/plugins 安装下载

    git clone https://github.com/zsh-users/zsh-syntax-highlighting.git

    然后激活这个插件,通过在

    vi ~/.zshrc 

    中找到plugins加入插件的名字

    plugins=(git zsh-syntax-highlighting)

    最后当然是source一下,让改变生效

    source ~/.zshrc

    6. 自动建议填充

    这个功能是非常实用的,可以方便我们快速的敲命令。

    配置步骤,先克隆zsh-autosuggestions项目,到指定目录:

    $ git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions

    然后编辑vim ~/.zshrc文件,找到plugins配置,增加zsh-autosuggestions插件。

    最后当然是source一下,让改变生效

    source ~/.zshrc

    注:上面声明高亮,如果配置不生效的话,在plugins配置,再增加zsh-syntax-highlighting插件试试。

    有时候因为自动填充的颜色和背景颜色很相似,以至于自动填充没有效果,我们可以手动更改下自动填充的颜色配置,我修改的颜色值为:586e75,示例:

    7. iTerm2 快速隐藏和显示

    这个功能也非常使用,就是通过快捷键,可以快速的隐藏和打开 iTerm2,示例配置(Commond + .):

    8. iTerm2 隐藏用户名和主机名

    有时候我们的用户名和主机名太长,比如我的xishuai@xishuaideMacBook-Pro,终端显示的时候会很不好看(上面图片中可以看到),我们可以手动去除。

    看起来你用的是 item2 + oh-my-zsh 组合,假如你用的主题是 agnoster,修改方法是进入 oh-my-zsh/themes/然后 vi agnoster.zsh-theme,编辑主题配置文件,找到如下代码:

    # Context: user@hostname (who am I and where am I)
    prompt_context() {
      if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
       # 修改如下代码,@Mac可以你自己定义
       # prompt_segment black default "%(!.%{%F{yellow}%}.)$USER@%m"
       prompt_segment black default "$"
      fi
    }

    9.最终的效果展示

  • 相关阅读:
    DNNClassifier 深度神经网络 分类器
    浏览器对MP4视频 帧宽度 高度的兼容性
    UnicodeEncodeError:'latin-1' codec can't encode character
    文件夹下 文件计数
    the largest value you actually can transmit between the client and server is determined by the amount of available memory and the size of the communications buffers.
    the “identity” of an object
    广告特征 用户特征
    如果一个维度全覆盖,则有效维度应该对该维度全覆盖
    a high-level neural networks AP
    使用 LDA 挖掘的用户喜好主题
  • 原文地址:https://www.cnblogs.com/Dylansuns/p/12307501.html
Copyright © 2011-2022 走看看