brew 无法安装iterm2_Mac系统iTerm2+oh-my-zsh配置及常用插件
iTerm2,是目前Mac平臺最好用,功能最強大的終端軟件,可以說是Mac系統下終端利器。Mac系統默認使用的終端為bash(MacOS Catalina開始,默認終端已經變成zsh);zsh被喻為“終極Shell”,讓其發揮強大功能設置過于復雜,而 oh-my-zsh 正是解決這一問題。本文將整理iTerm2+oh-my-zsh的配置和常用插件。
安裝iTerm2
前往官網下載最新版iTerm2,https://www.iterm2.com/downloads.html ,當前版本為3.2.9,下載后是一個zip壓縮包,解壓后放到 /Applications 目錄。雙擊運行即可。貼一段官網簡介:
What is iTerm2?
iTerm2 is a replacement for Terminal and the successor to iTerm. It works on Macs with macOS 10.12 or newer. iTerm2 brings the terminal into the modern age with features you never knew you always wanted.
安裝 oh-my-zsh
我使用wget方式安裝,在終端執行如下代碼:
sh -c "$(wget -O- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
注意:安裝前請先確認一些必要條件。
1.zsh
Mac系統應該是默認安裝了zsh ,如果不確定,在命令執行:cat /etc/shells 會列出系統中預裝的shell。出現如圖信息說明系統已經預裝zsh,如果沒有需要安裝zsh,可以使用brew 方式(brew install zsh),或參考:https://github.com/robbyrussell/oh-my-zsh/wiki/Installing-ZSH
安裝好zsh后,需要將系統默認shell切換為zsh:
chsh -s /bin/zsh
可以通過echo $SHELL 查看當前默認的shell,如果默認shell不是zsh,需要重啟iTerm2。
2.curl 或 wget
我使用curl方式安裝,在終端輸入curl --version 檢查是否安裝,如顯示“command not found”,可使用brew安裝(brew install curl)。使用wget方式同理。更多方式參考:https://github.com/robbyrussell/oh-my-zsh#basic-installation
3.git
git,用于后期 oh-my-zsh 的擴展功能安裝,如主題或插件。在終端輸入git --version 檢查是否安裝,方法與curl相同,可以通過brew安裝(brew install git)。
oh-my-zsh 主題配置
oh-my-zsh 主題在 ~/.oh-my-zsh/themes 目錄。可通過 ls ~/.oh-my-zsh/themes 查看所有主題。每個主題具體樣式可參考:https://github.com/robbyrussell/oh-my-zsh/wiki/Themes ;主題很多,總有一款適合自己。
如果更換主題?
編輯 ~/.zshrc 文件,將 ZSH_THEME=“candy” 的 candy 換成對應主題名字即可。
這是我自己編輯并使用的主題文件,供大家參考:
local ret_status="%(?:%{$fg_bold[green]%}? :%{$fg_bold[red]%}? )"
PROMPT='${ret_status} %{$fg[cyan]%}%~%{$reset_color%} $(git_prompt_info)# '
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}git:(%{$fg[red]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}?"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})"
如果增加擴展插件?
我不是終端重度用戶,所以只使用了兩個插件:
zsh-autosuggestions
zsh-syntax-highlighting
zsh-autosuggestions 安裝
git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
編輯 ~/.zshrc 文件,找到 plugins=(git) ,在git后增加 zsh-autosuggestions 即可(注意git和zsh-autosuggestions之間使用空格分隔)
zsh-syntax-highlighting 安裝
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
使用插件方法跟zsh-autosuggestions相同。
總結
以上是生活随笔為你收集整理的brew 无法安装iterm2_Mac系统iTerm2+oh-my-zsh配置及常用插件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 加油1150元,跑了900公里,还剩40
- 下一篇: 大缸烤肉多少时间能熟?