# Mac Terminal Settings 安裝、設定方式 總共有以下步驟: 1. 安裝 iTerm2 2. 安裝 powerline font 3. 安裝 zsh, oh-my-zsh 4. 設定 zsh theme: powerlevel10k 5. 設定 zsh: Auto suggestions, syntax highlighting ## 1. 安裝 iTerm2 ```shell brew install iterm2 ``` 安裝好以後,打開 iTerm2 設定路徑: ` Preferences > Profiles > Terminal > Report Terminal Type ` 檢查設定是否為 xterm-256color 然後下載 [iterm2 的 color themes](https://github.com/mbadolato/iTerm2-Color-Schemes) 為 zip file,並從中挑選一個主題(需先 import 再選定使用)。 --- ## 2. 安裝 Powerline font ```shell brew tap homebrew/cask-fonts brew install font-sauce-code-pro-nerde-font ``` 接者設定 iTerm2 字型,`Preferences > Profiles > Text > Change Font` --- ## 3. 安裝 zsh, Oh my zsh ### 安裝 zsh ``` brew install zsh ``` ### 安裝 oh-my-zsh ```bash sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" ``` 此時會詢問預設 shell 是否改為使用 zsh;若未詢問或未成功,則需輸入 ```bash sudo sh -c "echo $(which zsh) >> /etc/shells" chsh -s $(which zsh) ``` --- ## 4. 設定 powerlevel10k powerlevel10k 插件支援顯示多項的基本資訊。除了 zsh 提供顯示 current git branch 之外,還能顯示:「WiFi 訊號強度、筆電電池電力、CPU loading 及 system free memory … 等等。」 直接 clone 該插件到 oh-my-zsh 的客製主題資料夾 ```shell git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k ``` 安裝完之後需要 restart zsh 來進到下一步 下一步是修改 zsh 的設定檔,以調整 powerlevel 顯示的 UI 及資訊 此時會有自動跳出的一連串問答,完成後,zsh 設定檔就搞定了 ``` p10k configure ``` ## 5. Auto suggestions / Syntax highlighting ### zsh-auto-suggestions ```shell git clone https://github.com/zsh-users/zsh-autosuggestions.git $ZSH_CUSTOM/plugins/zsh-autosuggestions ``` ### zsh-syntax-highlighting ```shell git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting ``` 此時還未完整安裝,接著修改設定 ```bash vim ~/.zshrc # 將 plugins 多補上這兩個 plugins plugins=(git zsh-autosuggestions zsh-syntax-highlighting) ``` 到此算是大功告成了 ## 6. zshrc 自動識別 node.js 版本 在 ~/.zshrc 加入下面那段,會依照專案內根目錄的 .nvmrc 內設定版本自動切換 Node.js版本,電腦未安裝的 Node.js 版本也會自動安裝。 ```bash= autoload -U add-zsh-hook load-nvmrc() { local node_version="$(nvm version)" local nvmrc_path="$(nvm_find_nvmrc)" if [ -n "$nvmrc_path" ]; then local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")") if [ "$nvmrc_node_version" = "N/A" ]; then nvm install elif [ "$nvmrc_node_version" != "$node_version" ]; then nvm use fi elif [ "$node_version" != "$(nvm version default)" ]; then echo "Reverting to nvm default version" nvm use default fi } add-zsh-hook chpwd load-nvmrc load-nvmrc ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up