--- title: "Powerline: 終端機界面小工具" tags: Ubuntu --- # Powerline: 終端機界面小工具 ## 簡介 Powerline 是一個終端機的外掛小工具,支援各種常見的 Shell 與 Vim,可以讓命令提示字元與 Vim 的狀態列更美觀易讀。 ## 安裝 1. Ubuntu 14.04 之後的版本,可以直接使用以下指令安裝 ```bash sudo apt-get install powerline ``` 2. 下載 Powerline 字型與 fontconfig 字型設定檔 ```bash wget https://github.com/powerline/powerline/raw/develop/font/PowerlineSymbols.otf wget https://github.com/powerline/powerline/raw/develop/font/10-powerline-symbols.conf ``` 3. 將 PowerlineSymbols.otf 字型放入字型目錄 ```bash mv PowerlineSymbols.otf ~/.fonts/ ``` 4. 更新字型快取 ```bash fc-cache -vf ~/.fonts/ ``` 5. 將字型設定檔放進適當的目錄 ```bash mv 10-powerline-symbols.conf ~/.config/fontconfig/conf.d/ ``` ## 設定 ### Bash Shell 1. 在 `~/.bashrc` 中加入下列程式碼 ```bash POWERLINE_SCRIPT=/usr/share/powerline/bindings/bash/powerline.sh if [ -f $POWERLINE_SCRIPT ]; then source $POWERLINE_SCRIPT fi ``` 2. 修改設定,以顯示 git branch 1. 開啟 `~/.config/powerline/config.json` 2. 將 `shell` 內的 `theme` 的設定值由 `default` 改為 `default_leftonly` ```json "shell": { "colorscheme": "default", "theme": "default_leftonly", "local_themes": { "continuation": "continuation", "select": "select" ``` 3. 重新開啟終端機,即可看到 Powerline 的效果 ### Vim 在 `~/.vimrc` 中加入下列設定 ```vim set laststatus=2 set t_Co=256 ``` --- ## 參考資料 * [Powerline:漂亮的 Vim 狀態列與 Bash Shell 命令提示字串外掛](https://blog.gtwang.org/linux/powerline-adds-powerful-statuslines-and-prompts-to-vim-and-bash/) * [Configuring powerline to show working Git branch.](https://leifmadsen.wordpress.com/2015/09/09/configuring-powerline-to-show-working-git-branch/) * [Patched fonts for Powerline users.](https://github.com/powerline/fonts)