# 從頭開始配置 Terminal ## 安裝 iTerm2 https://iterm2.com/downloads.html :::spoiler ``` brew tap homebrew/cask brew install --cask iterm2 ``` ::: ## 安裝 zsh ### Mac 先安裝 Homebrew ```sh /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` 再透過 Homebrew 安裝 Zsh ```sh brew install zsh ``` ### Debian(例如 Raspberry Pi OS 或 Ubuntu) 直接透過 apt 安裝 Zsh ```sh sudo apt update sudo apt install zsh -y ``` :::spoiler `sudo sh -c "echo $(which zsh) >> /etc/shells"`: 雖然 zsh 可能已經安裝並可執行,但如果它不在 /etc/shells 中,某些系統服務和程序可能不會將其識別為一個合法的 shell。添加後,你可以使用 chsh 命令安全地將 zsh 設為用戶的默認 shell。 - `sudo`: 以 root 權限運行命令。 - `sh -c`: 使用 shell 執行指定的命令。 - `echo $(which zsh)`: 尋找 `zsh` 的絕對路徑。 - `>> /etc/shells`: 將找到的 `zsh` 路徑追加到 `/etc/shells` 文件中。 `chsh -s $(which zsh)`: 這個命令將當前用戶的默認 shell 更改為 `zsh`。 - `chsh`: 更改用戶登錄後使用的 shell。 - `-s`: 指定新的 shell。 - `$(which zsh)`: 獲取 `zsh` 的絕對路徑。 ::: ## 安裝 oh-my-zsh ```sh sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" ``` > ### 把 Zsh 設定為預設 shell > > 在安裝 oh-my-zsh 的過程中,應該就會詢問是否將 zsh 設成預設 shell 了,沒有的話可以手動執行以下: > > ``` > sudo sh -c "echo $(which zsh) >> /etc/shells" > chsh -s $(which zsh) > ``` ## 安裝 powerlevel10k ``` git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k ``` :::spoiler 下載完後,要手動把 `~/.zshrc` 內的 `ZSH_THEME` 的值更新成 `"powerlevel10k/powerlevel10k"` ```diff - ZSH_THEME="robbyrussell" + ZSH_THEME="powerlevel10k/powerlevel10k" ``` ::: ## 安裝插件 ``` git clone --depth=1 https://github.com/zsh-users/zsh-completions ${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/plugins/zsh-completions git clone --depth=1 https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions git clone --depth=1 https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting ``` :::spoiler 實際上下載完後,還要手動將以下加入至 `~/.zshrc` ```= plugins=( git zsh-completions zsh-autosuggestions zsh-syntax-highlighting ) ``` ::: ## 🧸 下載設定值 參考以下 README,根據個人喜好分別執行指令來下載設定值。 **留意它會覆蓋掉目的地檔案,務必想清楚再操作**。 - Download my .zshrc - Download my .p10k.zsh - Download my alias.zsh https://github.com/ngseke/dotfiles ## 安裝推薦字體 第一次執行此指令時,會詢問是否安裝 `Meslo Nerd Font` ``` p10k configure ``` ## 套用變更 ``` source ~/.zshrc ``` ## Troubleshooting - [看不見 suggestion:可能與 iTerm > Profile > Color 設定有關](https://github.com/zsh-users/zsh-autosuggestions/issues/416#issuecomment-486516333) ## Reference - [【分享】Oh My Zsh + powerlevel10k 快速打造好看好用的 command line 環境 | by Holy | Medium](https://medium.com/statementdog-engineering/prettify-your-zsh-command-line-prompt-3ca2acc967f) - [超簡單!十分鐘打造漂亮又好用的 zsh command line 環境 | by Gary Chu | 財報狗技術部落格 | Medium](https://holychung.medium.com/%E5%88%86%E4%BA%AB-oh-my-zsh-powerlevel10k-%E5%BF%AB%E9%80%9F%E6%89%93%E9%80%A0%E5%A5%BD%E7%9C%8B%E5%A5%BD%E7%94%A8%E7%9A%84-command-line-%E7%92%B0%E5%A2%83-f66846117921)