mac使用iterm
一、安裝
1. 安裝iterm2
2. 使用oh-my-zsh
wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh
3. cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
4. vim ~/.zshrc
ZSH_THEME="robbyrussell" 默認主題
[https://github.com/robbyrussell/oh-my-zsh/wiki/Themes]() 每個主題的說明
主題文件在 ~/.oh-my-zsh/themes
編輯這個主題
vim ~/.oh-my-zsh/themes/robbyrussell.zsh-theme
修改這段
PROMPT='${ret_status} %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)'
在後面加了一個“>”, 其中%c 修改d 顯示的是目錄
修改爲
PROMPT='${ret_status} %{$fg[cyan]%}%d%{$reset_color%} $(git_prompt_info)>'
二 配置插件
安裝插件
autojump
是一個命令行工具,它允許你可以直接跳到喜歡的目錄
brew install autojump
修改.zshrc
[[ -s ~/.autojump/etc/profile.d/autojump.sh ]] && . ~/.autojump/etc/profile.d/autojump.sh
自動提示命令
zsh-autosuggestions
git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
打開vim .zshrc 文件
plugins=(
zsh-autosuggestions git
)
打開終端之後,有些字體太淡了,修改
cd ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
vim zsh-autosuggestions.zsh
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=10'
ls
Mac OS X是基於 FreeBSD 的,所以一些工具 ls, top 等都是 BSD 那一套,ls 不是 GNU ls,所以即使 Terminal/iTerm2 配置了顏色,但是在 Mac 上敲入 ls 命令也不會顯示高亮,可以通過安裝 coreutils 解決
brew install coreutils
zsh-syntax-highlighting
語法高亮
brew install zsh-syntax-highlighting
vim .zshrc
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
自定義別名
vim ~.zshrc
alias cls='clear'
alias ll='ls -l'
alias la='ls -a'
alias vi='vim'
alias grep="grep --color=auto"
配色
[https://iterm2colorschemes.com/]()
1. 下載
git clone https://github.com/mbadolato/iTerm2-Color-Schemes.git
2.導入
iterm2 -> preferences -> profiles -> colors
![](https://s1.51cto.com/images/blog/201807/25/3ee067cb4ff4871b2b6739511aede475.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
選擇import 導入下載下來的顏色schemes或者下載對應的xxx.itermcolors 文件導入即可
可以選擇自己喜歡的顏色了
ssh 替換爲mosh
brew install mobile-shell
主題
powerlevel9k 主題安裝
[https://github.com/bhilburn/powerlevel9k]()
git clone https://github.com/bhilburn/powerlevel9k.git ~/.oh-my-zsh/custom/themes/powerlevel9k
vim ~/.zshrc:
ZSH_THEME="powerlevel9k/powerlevel9k"
亂碼解決
安裝powerline-fonts
# clone
git clone https://github.com/powerline/fonts.git --depth=1
# install
cd fonts
./install.sh
# clean-up a bit
cd ..
rm -rf fonts
選擇字體
設置字體
安裝awesome 字體
[(https://github.com/gabrielelana/awesome-terminal-fonts/wiki/OS-X]()
vim ~/.zshrc
追加在後面
POWERLEVEL9K_PROMPT_ON_NEWLINE=true
POWERLEVEL9K_RPROMPT_ON_NEWLINE=true
POWERLEVEL9K_MODE='awesome-fontconfig'
POWERLEVEL9K_SHORTEN_DIR_LENGTH=1
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(os_icon dir vcs)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status)
POWERLEVEL9K_OS_ICON_BACKGROUND="white"
POWERLEVEL9K_OS_ICON_FOREGROUND="blue"
POWERLEVEL9K_DIR_HOME_FOREGROUND="white"
POWERLEVEL9K_DIR_HOME_SUBFOLDER_FOREGROUND="white"
POWERLEVEL9K_DIR_DEFAULT_FOREGROUND="white"
POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX="%f"
local user_symbol="$"
if [[ $(print -P "%#") =~ "#" ]]; then
user_symbol = "#"
fi
POWERLEVEL9K_MULTILINE_LAST_PROMPT_PREFIX="%{%B%F{black}%K{yellow}%} $user_symbol%{%b%f%k%F{yellow}%} %{%f%}"
效果如下
但是每次登陸需要source ~/.zshrc
具體參數參考
[https://github.com/bhilburn/powerlevel9k]()
[https://github.com/bhilburn/powerlevel9k/wiki/Stylizing-Your-Prompt]()
[https://github.com/bhilburn/powerlevel9k/wiki/Troubleshooting]()
我的github 地址
[https://github.com/xingxing9688/mac-shell]()