自从走上了Linux这条路,就离不开终端了。。。

如果不好好折腾一下,真是对不起自己的老花眼了!

所以老高针对Mac(没有的赶紧买买买)下的iterm2进行了简单的定制,记录如下:

Screen Shot 2015-11-25 at 7.11.28 PM.png

ps.此文会不定期更新

准备

什么!? 你还没有装iterm2、zsh和oh_my_zsh?

iterm2(目前最新版2.1.4) ---> 下载地址

zsh ---> 安装教程

安装powerline-shell

可以参考README安装:

powerline-shell on github.com

可能遇到的问题

安装powerline字体,参考README安装:

powerline/fonts on github.com

报错/usr/bin/env: python2: No such file or directory

解决:

ln -s /usr/bin/python /usr/bin/python2

换主题

下载solarized主题

目测就solarized的dark版能看。。。

github地址

老高从github抓的,放心用吧

coding地址

git clone https://github.com/altercation/solarized
# 老高从github抓的,放心用
git clone https://git.coding.net/phpgao/solarized.git

设置iterm主题

load新主题

在iterm2在设置-->Profiles-->Colors-->Load Presets 里导入刚才clone下来的iterm2-colors-solarized/Solarized Dark.itermcolors,然后选择即可!

solarized主题的选择文字不好分辨,可以刚好在此设置一下!

设置字体

在设置-->Profiles-->Text中把字体都设置为带Powerline后缀的,目测ubuntu和Meslo系列的字体比较耐看!

设置zsh

ps.这里最重要!

创建新主题文件

在文件夹~/.oh-my-zsh/themes中新建主题文件,名称自定:如laogao.zsh-theme,后面会用到。

下面的内容参考Mac OS X & Oh My ZSH Theme on iTerm2,将下面的内容保存到刚才的文件中!

if [ "$POWERLINE_DATE_FORMAT" = "" ]; then
  POWERLINE_DATE_FORMAT=%D{%Y-%m-%d}
fi

if [ "$POWERLINE_RIGHT_B" = "" ]; then
  POWERLINE_RIGHT_B=%D{%H:%M:%S}
elif [ "$POWERLINE_RIGHT_B" = "none" ]; then
  POWERLINE_RIGHT_B=""
fi

if [ "$POWERLINE_RIGHT_A" = "mixed" ]; then
  POWERLINE_RIGHT_A=%(?."$POWERLINE_DATE_FORMAT".%F{red}✘ %?)
elif [ "$POWERLINE_RIGHT_A" = "exit-status" ]; then
  POWERLINE_RIGHT_A=%(?.%F{green}✔ %?.%F{red}✘ %?)
elif [ "$POWERLINE_RIGHT_A" = "date" ]; then
  POWERLINE_RIGHT_A="$POWERLINE_DATE_FORMAT"
fi

if [ "$POWERLINE_HIDE_USER_NAME" = "" ] && [ "$POWERLINE_HIDE_HOST_NAME" = "" ]; then
    POWERLINE_USER_NAME="%[email protected]"'%M'
elif [ "$POWERLINE_HIDE_USER_NAME" != "" ] && [ "$POWERLINE_HIDE_HOST_NAME" = "" ]; then
    POWERLINE_USER_NAME="@%M"
elif [ "$POWERLINE_HIDE_USER_NAME" = "" ] && [ "$POWERLINE_HIDE_HOST_NAME" != "" ]; then
    POWERLINE_USER_NAME="%n"
else
    POWERLINE_USER_NAME="λ"
fi

POWERLINE_CURRENT_PATH="%d"

if [ "$POWERLINE_FULL_CURRENT_PATH" = "" ]; then
  POWERLINE_CURRENT_PATH="%1~"
fi

if [ "$POWERLINE_GIT_CLEAN" = "" ]; then
  POWERLINE_GIT_CLEAN="✔"
fi

if [ "$POWERLINE_GIT_DIRTY" = "" ]; then
  POWERLINE_GIT_DIRTY="✘"
fi

if [ "$POWERLINE_GIT_ADDED" = "" ]; then
  POWERLINE_GIT_ADDED="%F{green}✚%F{black}"
fi

if [ "$POWERLINE_GIT_MODIFIED" = "" ]; then
  POWERLINE_GIT_MODIFIED="%F{blue}✹%F{black}"
fi

if [ "$POWERLINE_GIT_DELETED" = "" ]; then
  POWERLINE_GIT_DELETED="%F{red}✖%F{black}"
fi

if [ "$POWERLINE_GIT_UNTRACKED" = "" ]; then
  POWERLINE_GIT_UNTRACKED="%F{yellow}✭%F{black}"
fi

if [ "$POWERLINE_GIT_RENAMED" = "" ]; then
  POWERLINE_GIT_RENAMED="➜"
fi

if [ "$POWERLINE_GIT_UNMERGED" = "" ]; then
  POWERLINE_GIT_UNMERGED="═"
fi

ZSH_THEME_GIT_PROMPT_PREFIX=" \ue0a0 "
ZSH_THEME_GIT_PROMPT_SUFFIX=""
ZSH_THEME_GIT_PROMPT_DIRTY=" $POWERLINE_GIT_DIRTY"
ZSH_THEME_GIT_PROMPT_CLEAN=" $POWERLINE_GIT_CLEAN"

ZSH_THEME_GIT_PROMPT_ADDED=" $POWERLINE_GIT_ADDED"
ZSH_THEME_GIT_PROMPT_MODIFIED=" $POWERLINE_GIT_MODIFIED"
ZSH_THEME_GIT_PROMPT_DELETED=" $POWERLINE_GIT_DELETED"
ZSH_THEME_GIT_PROMPT_UNTRACKED=" $POWERLINE_GIT_UNTRACKED"
ZSH_THEME_GIT_PROMPT_RENAMED=" $POWERLINE_GIT_RENAMED"
ZSH_THEME_GIT_PROMPT_UNMERGED=" $POWERLINE_GIT_UNMERGED"
ZSH_THEME_GIT_PROMPT_AHEAD=" ⬆"
ZSH_THEME_GIT_PROMPT_BEHIND=" ⬇"
ZSH_THEME_GIT_PROMPT_DIVERGED=" ⬍"

if [ "$POWERLINE_SHOW_GIT_ON_RIGHT" = "" ]; then
    if [ "$POWERLINE_HIDE_GIT_PROMPT_STATUS" = "" ]; then
        POWERLINE_GIT_INFO_LEFT=" %F{blue}%K{white}"$'\ue0b0'"%F{white}%F{black}%K{white}"$'$(git_prompt_info)$(git_prompt_status)%F{white}'
    else
        POWERLINE_GIT_INFO_LEFT=" %F{blue}%K{white}"$'\ue0b0'"%F{white}%F{black}%K{white}"$'$(git_prompt_info)%F{white}'
    fi
    POWERLINE_GIT_INFO_RIGHT=""
else
    POWERLINE_GIT_INFO_LEFT=""
    POWERLINE_GIT_INFO_RIGHT="%F{white}"$'\ue0b2'"%F{black}%K{white}"$'$(git_prompt_info)'" %K{white}"
fi

if [ $(id -u) -eq 0 ]; then
    POWERLINE_SEC1_BG=%K{red}
    POWERLINE_SEC1_FG=%F{red}
else
    POWERLINE_SEC1_BG=%K{green}
    POWERLINE_SEC1_FG=%F{green}
fi
POWERLINE_SEC1_TXT=%F{black}
if [ "$POWERLINE_DETECT_SSH" != "" ]; then
  if [ -n "$SSH_CLIENT" ]; then
    POWERLINE_SEC1_BG=%K{red}
    POWERLINE_SEC1_FG=%F{red}
    POWERLINE_SEC1_TXT=%F{white}
  fi
fi
PROMPT="$POWERLINE_SEC1_BG$POWERLINE_SEC1_TXT $POWERLINE_USER_NAME %k%f$POWERLINE_SEC1_FG%K{blue}"$'\ue0b0'"%k%f%F{white}%K{blue} "$POWERLINE_CURRENT_PATH"%F{blue}"$POWERLINE_GIT_INFO_LEFT" %k"$'\ue0b0'"%f "

if [ "$POWERLINE_NO_BLANK_LINE" = "" ]; then
    PROMPT="
"$PROMPT
fi

if [ "$POWERLINE_DISABLE_RPROMPT" = "" ]; then
    if [ "$POWERLINE_RIGHT_A" = "" ]; then
        RPROMPT="$POWERLINE_GIT_INFO_RIGHT%F{white}"$'\ue0b2'"%k%F{black}%K{white} $POWERLINE_RIGHT_B %f%k"
    elif [ "$POWERLINE_RIGHT_B" = "" ]; then
        RPROMPT="$POWERLINE_GIT_INFO_RIGHT%F{white}"$'\ue0b2'"%k%F{240}%K{white} $POWERLINE_RIGHT_A %f%k"
    else
        RPROMPT="$POWERLINE_GIT_INFO_RIGHT%F{white}"$'\ue0b2'"%k%F{black}%K{white} $POWERLINE_RIGHT_B %f%F{240}"$'\ue0b2'"%f%k%K{240}%F{255} $POWERLINE_RIGHT_A %f%k"
    fi
fi

编辑.zshrc

讲下面的内容追加到你的~/.zshrc文件中!


ZSH_THEME="laogao"

POWERLINE_HIDE_USER_NAME="true"
POWERLINE_HIDE_HOST_NAME="true"
POWERLINE_DETECT_SSH="true"
POWERLINE_GIT_CLEAN="✔"
POWERLINE_GIT_DIRTY="✘"
POWERLINE_GIT_ADDED="%F{green}✚%F{black}"
POWERLINE_GIT_MODIFIED="%F{blue}✹%F{black}"
POWERLINE_GIT_DELETED="%F{red}✖%F{black}"
POWERLINE_GIT_UNTRACKED="%F{yellow}✭%F{black}"
POWERLINE_GIT_RENAMED="➜"
POWERLINE_GIT_UNMERGED="═"

# 开启等待红点
COMPLETION_WAITING_DOTS="true"

# 加入一些插件
plugins=(git autojump mvn gradle brew rails3 git-flow capistrano zeus textmate ruby osx)

source $ZSH/oh-my-zsh.sh

删除OMZ

如果用腻了想删除,很简单!

rm ~/.oh-my-zsh

标签: zsh

已有 16 条评论

  1. 杨宇 杨宇

    老高,我的oh my ssh 配置好以后进去是这样的 λ ? ~ ? ? 不知道哪里来的问号,我是英文系统,完全按照你的教程来的

    1. Zhu Zhu

      修改主题文件,把λ 改成你想要的名字就好了

  2. fisherman 是一款零配置,并发的 fish shell 插件管理器。
    https://github.com/fisherman/fisherman/tree/master/docs/zh-CN

    1. 不错,以后试试

      1. https://github.com/fisherman/fisherman/wiki/%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87

  3. ymqy ymqy

    老高,谢谢你,花了一下午在研究,不停的试错,这次终于弄好了,时间花了很多,但是过程很享受^_^,就是还有一个问题想请教下,怎么把这些”YeMing  YeMingdeMacBook-Pro“换成简短的字符代替,基本被这些占的没地方

    1. 在oh my zsh的rc文件里改

      1. ymqy ymqy

        老高,我好像出问题了,按道理复制了你的代码应该和你显示的一样,为什么我的user和hostname又出来了,我再琢磨看看

        1. if [ "$POWERLINE_HIDE_USER_NAME" = "" ] && [ "$POWERLINE_HIDE_HOST_NAME" = "" ]; then
          POWERLINE_USER_NAME="%[email protected]"'%M'
          elif [ "$POWERLINE_HIDE_USER_NAME" != "" ] && [ "$POWERLINE_HIDE_HOST_NAME" = "" ]; then
          POWERLINE_USER_NAME="@%M"
          elif [ "$POWERLINE_HIDE_USER_NAME" = "" ] && [ "$POWERLINE_HIDE_HOST_NAME" != "" ]; then
          POWERLINE_USER_NAME="%n"
          else
          POWERLINE_USER_NAME="λ"
          fi

          这一段换成 POWERLINE_USER_NAME="λ"

          1. 改完要source或者注销一下才能看到变化

          2. ymqy ymqy

            还是不行,看来想完全弄好,应该从根本把这些代码看懂弄懂,老高这些都是shell编程语言吗还是什么,我想学会自己去定制按照自己的想法

  4. stirp stirp

    我用了fish和oh-my-fish……其实大同小异

    1. asins asins

      oh-my-fish是基于fish做的插件管理器噢,两者不是对立的。

  5. ymqy ymqy

    如何删除 我要重装,上次没有设置好

  6. ymqy ymqy

    ➜ ~ ln -s ~/powerline-shell.py zsh: no such file or directory: path/to/powerline-shell.py 老高这个如何解决?

    1. sudo brew install zsh 也试过了

    2. bash-3.2# brew install zsh Error: Cowardly refusing to `sudo brew install` You can use brew with sudo, but only if the brew executable is owned by root. However, this is both not recommended and completely unsupported so do so at your own risk. bash-3.2# 现在用root权限,变成这样

    3. ymqy ymqy

      Add the following to your .zshrc 修改后’➜ ~ ‘这个都没有了 ,是添加到最后一行吧 ZSH: Add the following to your .zshrc: function powerline_precmd() { PS1="$(~/powerline-shell.py $? --shell zsh 2> /dev/null)" } function install_powerline_precmd() { for s in "${precmd_functions[@]}"; do if [ "$s" = "powerline_precmd" ]; then return fi done precmd_functions+=(powerline_precmd) } if [ "$TERM" != "linux" ]; then install_powerline_precmd fi

    4. 没有用root 登录

    5. 先不要急,继续配置

    6. ymqy ymqy

      ➜ powerline-shell git:(master) ./install.py env: python2: No such file or directory ➜ powerline-shell git:(master) ln -s /usr/bin/python /usr/bin/python2 ln: /usr/bin/python2: Operation not permitted

    7. 你没有root权限吗?

    8. ymqy ymqy

      这个以修改

    9. ymqy是我,我重来过一遍,其实漏了个问题,把install.py里面第一行#!/usr/bin/env python2改成#!/usr/bin/env python,这样可以吗,因为出现下面的问题,你的解决方法不能用

    10. 这一步是可选的

    11. ymqy ymqy

      修改zsh的配置文件.zshrc,还有这个在哪修改

添加新评论