終端機個人化、實用工具推薦

Share This Post

前言

想必大家都對終端機不陌生了,他就是一個黑底白字的文字介面,像這樣:

Untitled
Untitled

但是你有想過他可以長這樣嗎

Untitled
Untitled

以下就來介紹一些在終端機上實用的個人化插件和小工具


Windows

<aside> 👉 總之先把這個視窗跟 CMD 換掉🤣

Untitled

</aside>

Windows Terminal

簡介

Windows Terminal 是近期微軟新推出的終端機應用程式,為打破傳統命令提示字元而生,提供多設定檔切換和高度個人化,讓終端機不再是一個死板的黑白介面。

以下是微軟在一開始(2019)釋出的概念影片,雖然現在還是有點差異:

官方文件介紹:

Windows 終端機概觀


安裝

Windows 11 內建 Windows Terminal,除非你把他刪了

Windows 10 或 Windows 11 但已經刪掉的朋友們,可以透過以下連結安裝:

Get Windows Terminal from the Microsoft Store


設定及使用

  • 啟動 Windows Terminal

到開始功能表尋找「終端機」即可啟動 Windows Terminal

Untitled

<aside> 💡 For Windows 11:

可以透過對開始按鈕按右鍵的選單啟動 Windows Terminal

Untitled

</aside>

  • 設定 Windows Terminal

可透過這個頁面設定終端機行為和個人化,以下挑幾個重點設定介紹:

Untitled

<aside> ⚠️ 調整完設定記得按右下角的「儲存」

Untitled

</aside>

  1. 可透過新分頁右邊的箭頭開啟設定頁面
Untitled
  1. 設定預設設定檔
Untitled

<aside> 💡 For Windows 11:

可將預設終端機軟體設定成 Windows Terminal

Untitled

日後其他軟體要開終端機也會用 Windows Terminal 開啟

Untitled

</aside>

  1. 選擇終端介面的主題 Untitled
Untitled
Untitled
  1. 讓標題列變半透明
Untitled

<aside> ⚠️ 儲存設定後,需重開終端機才會生效

</aside>

Untitled
  1. 設定檔可以個別設定不同環境的終端軟體(如:CMD、PowerShell、Git Bash 等等)、外觀、圖示以及其他行為設定
Untitled

<aside> 💡 「預設值」設定會套用到所有設定檔

Untitled

</aside>

文字設定:設定字體、文字大小等基本設定

Untitled

背景影像:終端機的背景(對,可以終端機上放背景圖)

Untitled

透明度:可以讓終端機變半透明

Untitled
Untitled

其他個人化功能可以參考一下文件:

Windows 終端機概觀


補充:讓 Git Bash 成為 Windows Terminal 的一部份

Untitled

對的 Windows Terminal 也可以開 Git Bash,但是他預設是開的,因此大部分人都在安裝 Git 的時候忽略掉,此時可以透過重新安裝(不需要把原本的刪掉)將選項補開回來,也可以順便更新一下😃

  • Git for Windows 下載

Downloads

  1. 直接執行安裝檔,會出下以下畫面,請把 Only show new options 取消勾選,否則他會直接跳過選項直接安裝,接著按下 Next
Untitled
  1. 在下一個頁面,將 (NEW!) Add a Git Bash Profile to Windows Terminal 勾起來,也可以順便 Review 一下其他設定(例如自動更新、預設 Branch 名稱、預設 Git 編輯器等)如果沒有要調整其他設定,可以把 Only show new options 再次勾起來,跳過剩餘選項(但我還是推薦 review 一下),最後按 Install 安裝
Untitled

再次開啟 Windows Terminal,就會多出 Git Bash 的 Profile 了


PowerShell 7

簡介

Untitled

PowerShell 7 是微軟新推出的終端機,也是微軟第一個跨平台的 Shell,能提供比 CMD 更好的終端機使用體驗。

官方文件介紹

什麼是 PowerShell? – PowerShell

<aside> ⚠️ 別跟這個 PowerShell 搞混了,這是舊版的

Untitled

</aside>


安裝

在 Windows 上安裝 PowerShell – PowerShell

  • 或透過 Microsoft Store 安裝

Get PowerShell from the Microsoft Store


設定成 Windows Terminal 預設設定檔

安裝完 PowerShell 後,開啟 Windows Terminal 會自動新增 PowerShell 的設定檔,此時就可以將他設定成預設的終端機了

Untitled

設定成 Visual Studio Code 的預設終端機

  1. 啟動終端機,在新增終端機右邊的選單選擇預設設定檔
Untitled
  1. 選擇 PowerShell (pwsh.exe
Untitled

自訂終端機提示 – oh-my-posh

安裝完的 PowerShell 終端提示是長這樣,但是長的跟我一開始提到的樣子還是不太一樣。

Untitled

這時候就要開始介紹一個插件叫做 oh-my-posh,他可以將終端提示個人化,內建許多不同的主題,也可以自訂主題。

Luca 之前有介紹過一次,如果想回味一下可以參考一下網址:

Windows Oh My Posh

  • 安裝 oh-my-posh

透過 winget 安裝

winget install JanDeDobbeleer.OhMyPosh -s winget

<aside> ⚠️ 之前在用的時候有一種方式是透過安裝 PowerShell module 方式安裝,例如:

Install-Module oh-my-posh -Scope CurrentUser

但是現在已經不再支援,請改用 winget 等其他方式安裝

相關資訊:

PowerShell module | Oh My Posh

</aside>

啟用 oh-my-posh

  1. 使用文字編輯器(例如:VSCode)開啟 PowerShell 設定檔
code $profile
  1. 加上以下指令
oh-my-posh init pwsh | Invoke-Expression

之後重開 PowerShell,如果他長得像下面這個畫面就表示有成功

Untitled

<aside> ⚠️ 此時建議將整個終端軟體如 Windows Terminal 重啟,以重新載入環境變數

</aside>

<aside> 💡 你可能注意到了終端機啟動緩慢的警告,此為載入 oh-my-posh 的正常現象,通常不會超過 2000 ms

</aside>

相關文件:

Windows | Oh My Posh

Change your prompt | Oh My Posh

  • 安裝字體

眼尖的應該都發現了,為啥出現了一堆方框?

Untitled

oh-my-posh 和 Powerlevel10K 是基於 Nerd Font 設計的應用程式。請參閱 Nerd Font 安裝字體,安裝並設定完成後,如果提示跟下方圖示的長一樣,代表安裝成功。

Untitled
  • 設定主題
  1. 在 PowerShell 輸入以下指令取得內建主題列表
Get-PoshThemes
Untitled
  1. 選好主題後,記下他的名字,到最底下提供的路徑
Untitled

<aside> 💡 Windows Terminal 可以透過 Ctrl + 點一下路徑直接使用檔案總管開啟

</aside>

  1. 找到你選擇的主題,複製完整路徑
Untitled

<aside> 💡 Windows 11 的複製路徑按鈕在右鍵選單內

</aside>

  1. 使用文字編輯器(例如:VSCode)開啟 PowerShell 設定檔
code $profile
  1. 將剛剛的
oh-my-posh init pwsh | Invoke-Expression

取代成

oh-my-posh init pwsh --config <路徑> | Invoke-Expression

其中將 <路徑> 取代成剛剛複製的路徑即可

<aside> 💡 我在最一開始的主題不是內建的,是根據 Powerlevel10K 主題修改過的

Untitled
  • p10k.omp.json { "$schema": "<https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json>", "blocks": [ { "alignment": "left", "segments": [ { "background": "#303030", "foreground": "#eeeeee", "properties": { "windows": "\\ue70f" }, "style": "plain", "template": " {{ if .WSL }}WSL at {{ end }}{{.Icon}}<#707070> \\ue0b1</>", "type": "os" }, { "background": "#303030", "foreground": "#00afff", "properties": { "style": "letter" }, "style": "plain", "template": " {{ .Path }} ", "type": "path" }, { "background": "#303030", "foreground": "#5fd700", "properties": { "ahead_color": "#00afff", "behind_color": "#e91e63", "branch_icon": "\\ue725 ", "fetch_stash_count": true, "fetch_status": true, "fetch_upstream_icon": true }, "style": "plain", "template": "<#707070>\\ue0b1 </>{{ .HEAD }} {{ .BranchStatus }}{{ if .Working.Changed }} \\uf044 <#d7af00>{{ .Working.String }}</>{{ end }}{{ if and (.Staging.Changed) (.Working.Changed) }}{{ end }}{{ if .Staging.Changed }} \\uf046 <#00afff>{{ .Staging.String }}</>{{ end }}{{ if gt .StashCount 0}} \\uf692 {{ .StashCount }}{{ end }}{{ if gt .WorktreeCount 0}} \\uf1bb {{ .WorktreeCount }}{{ end }} ", "type": "git" }, { "background": "#303030", "foreground": "#e91e63", "properties": { "root_icon": "#" }, "style": "plain", "template": "<#707070>\\ue0b1 </>\\uf0e7 ", "type": "root" }, { "background": "transparent", "foreground": "#303030", "style": "plain", "template": "\\ue0b0 ", "type": "text" } ], "type": "prompt" }, { "alignment": "right", "segments": [ { "background": "#303030", "foreground": "#008000", "foreground_templates": [ "{{ if gt .Code 0 }}#e91e63{{ end }}" ], "leading_diamond": "\\ue0b2", "properties": { "always_enabled": true, "display_exit_code": true }, "style": "diamond", "template": " {{ if gt .Code 0 }}\\u2718 {{ .Meaning }}{{ else }}\\u2714 {{ end }}<#707070>\\ue0b3</>", "type": "exit" }, { "background": "#303030", "foreground": "#00afaf", "properties": { "display_mode": "environment" }, "style": "plain", "template": " \\ue235 {{ if .Error }}{{ .Error }}{{ else }}{{ if .Venv }}{{ .Venv }} {{ end }}{{ .Full }}{{ end }} ", "type": "python" }, { "background": "#303030", "properties": { "style": "round", "threshold": 500 }, "style": "plain", "template": " {{ .FormattedMs }} <#707070>\\ue0b3</>", "type": "executiontime" }, { "background": "#303030", "foreground": "#d7af87", "style": "plain", "template": " {{ if .SSHSession }}\\uf817 {{ end }}{{ .UserName }}@{{ .HostName }} <#707070>\\ue0b3</>", "type": "session" }, { "background": "#303030", "foreground": "#5f8787", "properties": { "time_format": "15:04:05" }, "style": "plain", "template": " {{ .CurrentDate | date .Format }} \\uf017 ", "type": "time" } ], "type": "rprompt" } ], "console_title_template": "{{if .Root}}# {{end}}{{.Folder}}", "version": 2 }

自訂方式我就不細說了,有興趣的可以自行參考自訂主題文件:

General | Oh My Posh

</aside>

<aside> 💡 關於 Python 虛擬環境

有些主題(如我在上面提供的自訂主題)有提供虛擬環境提示,可能會和預設的虛擬環境提示重複,像這樣:

Untitled

解決方式為開啟 PowerShell 設定檔

code $profile

加入以下指令以停用預設虛擬環境提示

$env:VIRTUAL_ENV_DISABLE_PROMPT = 1

效果如下

Untitled

</aside>


其他插件及設定

  • posh-git

posh-git 是讓 PowerShell 和 Git 整合的插件,以下是兩個主要功能:

  1. 提供 git 的狀態顯示
Untitled
  1. 提供 git 指令自動完成 posh-git.gif
https://github.com/dahlbyk/posh-git

安裝方式:

  1. 開啟 PowerShell,輸入
Install-Module posh-git

安裝時會出現以下的警告,表示從來源安裝模組是有風險的,按下 Y 接受

Untitled
  1. 使用文字編輯器(例如:VSCode)開啟 PowerShell 設定檔
code $profile
  1. 加上以下指令
Import-Module posh-git
  1. 如果你有安裝 oh-my-posh,可以在加上以下指令開啟整合
$env:POSH_GIT_ENABLED = $true

重啟 PowerShell 就會啟用

  • 歷史記錄搜尋

可快速執行之前執行過的指令,加速執行重複動作時的流程

readline-search.gif

設定方式

  1. 使用文字編輯器(例如:VSCode)開啟 PowerShell 設定檔
code $profile
Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward

重啟 PowerShell 就會啟用


Linux

<aside> 👉 Mac 應該也能用,我沒試過就是了

</aside>

<aside> 💡 以下以 APT 生態的 Ubuntu 系統為範例,但安裝方式大同小異

</aside>

Zsh & oh-my-zsh

簡介

Z shell (以下簡稱 Zsh)是一個終端機應用程式,改善了原始終端機(sh)的許多功能,並加入 Bash、ksh、tcsh 的某些功能。

ZSH – THE Z SHELL

而由社群維護的 oh-my-zsh 則是強化了 Zsh 。除了強化 Zsh 的許多功能,也且內建許多主題和插件,當然也可以額外加入其他主題和插件。

  • 豐富的插件
Untitled
  • 豐富的主題
Untitled

Themes · ohmyzsh/ohmyzsh Wiki

  • 更好的使用體驗 ohmyzsh.gif

安裝 ZSH & oh-my-zsh

大部分的套件管理工具都有 zsh 了,透過套件管理工具安裝 zsh 即可

Z shell – 维基百科,自由的百科全书

Oh My Zsh – a delightful & open source framework for Zsh

sudo apt install zsh

接著安裝 oh-my-zsh 需要的套件(系統可能會內建):

  • git
  • curl
sudo apt install git curl

然後安裝 oh-my-zsh

sh -c "$(curl -fsSL <https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh>)"

此時會詢問是否要將預設終端應用程式設定成 Zsh,按下 Enter (接受預設值 Y)並輸入密碼即可切換

Untitled

安裝完之後,出現這個提示即代表安裝成功

Untitled

此時建議您重新登入您的作業系統以套用變更,桌面環境需要重新登入整個桌面。

<aside> ⚠️ 如果重登後終端機設定沒有生效,則需要手動變更啟動終端機為 zsh

如需查看 zsh 的安裝位置,可利用以下指令:

which zsh

以 Konsole 為例,需要更改的是目前設定檔的這個欄位,輸入的是上方指令的結果

Untitled

</aside>


Powerlevel10K

Powerlevel10K 是一個 ZSH 主題,提供高度個人化的終端機提示

以下是幾個終端機提示的範例:

Untitled

GitHub – romkatv/powerlevel10k: A Zsh theme

<aside> 💡 oh-my-posh 和 Powerlevel10K 是基於 Nerd Font 設計的應用程式,因此推薦在安裝使用前先行將字體裝好,請參閱 Nerd Font 安裝字體。

</aside>

這裡我們將直接利用 oh-my-zsh 的主題系統安裝**:**

  1. 將主題 Clone 下來
git clone --depth=1 <https://github.com/romkatv/powerlevel10k.git> ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
  1. 打開 zsh 設定檔
vim ~/.zshrc
  1. 將主題設定為 Powerlevel10K:將原本的
ZSH_THEME="robbyrussell"

取代成

ZSH_THEME="powerlevel10k/powerlevel10k"
  1. 儲存 ~/.zshrc 檔案後,重新開啟終端,Powerlevel10k 就會開始設定精靈,逐步個人化您的終端機

<aside> 💡 選擇的方式直接按一下選項前面顯示的按鍵即可

</aside>

<aside> 💡 如果不小心選錯了可以按一下 r 重新開始精靈

</aside>

Untitled

首先會連續問四個問題以確認您的系統編碼和安裝的字體(底下都有附範例網址)

  • 這是否長得像鑽石?(Unicode 測試)
Untitled

  • 這是否長得像一個鎖?(確認字體圖示)
Untitled

lock | Font Awesome

  • 這是否長得像 Debian 圖示?(確認字體圖示)
Untitled

  • 圖示是否都剛好在 X 內(確認字體重疊)
Untitled

以上問題如果您有正確安裝 Nerd Font 都會正常顯示

接著會逐步詢問個人化的部分,請依照您的喜好選擇

Untitled

個人化選完後就會詢問這個問題,因為插件一多載入速度就會變慢,啟用這個就可以在 zsh 啟動時就開始有打字的回饋,這邊直接選建議值 Verbose 即可

Untitled

因為這個設定需要變更設定檔,接著會問你是否寫入 ~/.zshrc ,直接按 y 讓他幫你寫入

Untitled

跳出你選擇的終端提示主題後代表你已經設定成功

Untitled

<aside> 💡 日後想要變更選擇的話,可以執行以下指令重新開始精靈

p10k configure

</aside>


oh-my-zsh 插件

剛剛有提到 oh-my-zsh 有內建很多插件,很多插件都是提供自動完成功能,可以到以下連結查看所有插件

Plugins Overview · ohmyzsh/ohmyzsh Wiki

啟用插件

  1. 開啟 zsh 設定檔
vim ~/.zshrc
  1. 找到 Plugin= 開頭的那行,可以看到預設已經啟用 git 插件,可以整合 git 並提供 git 指令自動完成
Untitled
  1. 加上你想啟用的插件,用空格隔開
Untitled

<aside> 💡 畫面上啟用的插件,都是提供軟體整合(包括自動完成)的插件,可參考以下連結,視需要啟用插件

Plugins Overview · ohmyzsh/ohmyzsh Wiki

</aside>

<aside> ⚠️ 注意:越多插件啟用,終端機啟動速度越慢

</aside>

  1. ~/.zshrc 存檔並重開終端機,變更就會套用

其他 oh-my-zsh 插件

以下再介紹幾個沒有在官方插件庫的 oh-my-zsh 插件:

尚未被加入 Zsh 的自動填入腳本

Untitled
  1. 將插件 Clone 下來
git clone <https://github.com/zsh-users/zsh-completions> ${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/plugins/zsh-completions
  1. 將下方指令加到 ~/.zshrcsource $ZSH/oh-my-zsh.sh 前面
fpath+=${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/plugins/zsh-completions/src

<aside> ⚠️ 這個安裝方式有點不一樣,因為作者說使用一般插件的方式會有問題

oh-my-zsh installation instructions are sub-optimal · Issue #603 · zsh-users/zsh-completions

</aside>

指令格式提示,可以更清楚的看指令

Untitled
  1. 將插件 Clone 下來
git clone <https://github.com/zsh-users/zsh-syntax-highlighting.git> ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
  1. 透過上方提到的 啟用插件 方式啟用 zsh-syntax-highlighting

根據你打過的指令或自動完成提示指令

Untitled
  1. 將插件 Clone 下來
git clone <https://github.com/zsh-users/zsh-autosuggestions> ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
  1. 透過上方提到的 啟用插件 方式啟用 zsh-autosuggestions

nvm – Node.js 版本管理器整合

提供自動安裝 nvm 的功能,省去手動安裝的各種麻煩

使用說明請參考

  1. 將插件 Clone 下來
git clone <https://github.com/lukechilds/zsh-nvm> ~/.oh-my-zsh/custom/plugins/zsh-nvm
  1. 透過上方提到的 啟用插件 方式啟用 zsh-nvmnvm

Zsh5.8 以下的 systemctl 自動完成 Bug

關於在自動完成 systemctl 指令時會噴錯,此為已知問題,並且已經在 Zsh 5.9 修正。

Untitled

如果您的系統無法將 Zsh 升級到 5.9 (例如:Ubuntu 20.04)可以在 ~/.zshrc 最後面加上以下指令來暫時解決問題:

_systemctl_unit_state() {
  typeset -gA _sys_unit_state
  _sys_unit_state=( $(__systemctl list-unit-files "$PREFIX*" | awk '{print $1, $2}') )
}

ZSH Complaints “bad set of key/value pairs for associative array” for Completion of Service Name for systemctl · Issue #8751 · ohmyzsh/ohmyzsh


VIM

vim 是大家在 Linux 最熟悉的文字編輯器

Untitled

但你知道他也有插件系統嗎?

Vundle – Vim 插件管理系統

Vundle 全名 Vim bundle,是個插件管理系統

他可以…

  • 讓插件保持在 .vimrc
  • 一次安裝設定的所有插件
  • 一次更新所有的插件

等等

GitHub – VundleVim/Vundle.vim: Vundle, the plug-in manager for Vim

安裝方法:

  1. Clone 下來
git clone <https://github.com/VundleVim/Vundle.vim.git> ~/.vim/bundle/Vundle.vim
  1. 開啟 VIM 設定檔
vim ~/.vimrc
  1. 在最上方加入以下內容:
set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'

" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
" Plugin 'tpope/vim-fugitive'
" plugin from <http://vim-scripts.org/vim/scripts.html>
" Plugin 'L9'
" Git plugin not hosted on GitHub
" Plugin 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)
" Plugin 'file:///home/gmarik/path/to/plugin'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
" Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" Install L9 and avoid a Naming conflict if you've already installed a
" different version somewhere else.
" Plugin 'ascenator/L9', {'name': 'newL9'}

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList       - lists configured plugins
" :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line
  1. 重開 vim 輸入 :PluginInstall 初始化環境

出現 Done! 即安裝成功

Untitled

安裝插件

<aside> ⚠️ 本來想介紹使用 :PluginSearch ,不過他現在有點問題,所以就暫時不介紹了。

</aside>

  1. 開啟 VIM 設定檔
vim ~/.vimrc
  1. 找到 Plugin 'VundleVim/Vundle.vim' ,並在底下依照以下格式寫上要裝的插件
  • 範例: GitHub 上的插件
Plugin 'tpope/vim-fugitive'
  • 範例: 其他 Git 系統的插件
Plugin 'git://git.wincent.com/command-t.git'
  • 範例: 本機插件
Plugin 'file:///home/gmarik/path/to/plugin'

<aside> 💡 插件作者通常會在插件的 Readme 上寫上相關的安裝方式

</aside>

  1. 編輯存檔後,重開 vim 輸入 :PluginInstall

VIM 插件

在 VIM 內查看版本控制狀態

https://raw.githubusercontent.com/mhinz/vim-signify/master/pictures/signify-demo.gif

安裝方式

  1. 透過 安裝插件 的方式,加上下面這行
Plugin 'mhinz/vim-signify'
  1. 設定更新時間(單位是 ms,預設 4000 太慢了)
set updatetime=100

快速切換註解

gcc.gif

簡易使用方式:

  • gcc :註解/取消註解游標在的那行
  • 使用 Visual Mode 選取後按 gc :將選取範圍註解/取消註解
  • :7,17Commentary : 將 7~17 行註解/取消註解

安裝方式

  1. 透過 安裝插件 的方式安裝
Plugin 'tpope/vim-commentary'

好看的狀態列

Untitled
Untitled
Untitled
Untitled

安裝方式

  1. 透過 安裝插件 的方式,加上下面這行
Bundle 'powerline/powerline', {'rtp': 'powerline/bindings/vim/'}

Other plugins – Powerline beta documentation

  1. 讓狀態列永遠啟用:在 ./.vimrc 加上
set laststatus=2

提供跟其他 IDE 一樣的自動完成系統

Untitled

安裝方式

  1. 透過 安裝插件 的方式,加上下面這行
Plugin 'ycm-core/YouCompleteMe'
  1. 需要編譯語言伺服器和包含 Python 3.6 以上的 VIM,通常會內建,先檢查 VIM 使用的 Python 版本,打開 vim 按下 : 進入指令模式後打上
py3 import sys; print( sys.version )

如果出現以下訊息代表你的 VIM 有 python ,並列出 python 版本

Untitled

<aside> 💡 如果出現錯誤,代表您的 VIM 沒有 Python,請尋找適合你系統的安裝方法

</aside>

  1. 安裝所需套件和你要實現自動完成的所有語言
sudo apt install cmake build-essential python3-dev
  1. 切換到 You Complete Me 資料夾
cd ~/.vim/bundle/YouCompleteMe
  1. 開始編譯語言伺服器

<aside> 💡 這需要執行好一段時間,建議所有差建設定完後再執行

</aside>

python3 install.py

如果你想要安裝額外語言支援,可以參考以下參數說明指定想安裝的項目

GitHub – ycm-core/YouCompleteMe: A code-completion engine for Vim

例如:安裝 JavaScript 和 TypeScript 支援:

python3 install.py --ts-complete

或使用以下指令安裝所有語言支援,前提是 msbuildgonode 跟 npm 都要事先安裝好

python3 install.py --all
  1. 安裝完成後,可以透過以下方法測試一下,先開啟一個腳本檔案(不需要建立,我們沒有要存檔)
vim test.sh

輸入 cd ./ ,如果有出現類似自動完成的東西代表安裝完成

Untitled

其他 VIM 設定

  • 啟用行號
Untitled
set number
  • 啟用滑鼠移動 / 選取 vim-mouse.gif
set mouse=a

<aside> ⚠️ 啟用滑鼠後,終端機的預設滑鼠功能會被取代,如果需要存取就必須按住 Shift

</aside>


Misc.

neofetch

用豪華的方式查看系統資訊

Untitled

**安裝:**透過套件管理工具安裝 neofetch 即可

sudo apt install neofetch

nvm

Node.js 版本管理工具,可以快速切換 Node.js 的環境

GitHub – nvm-sh/nvm: Node Version Manager – POSIX-compliant bash script to manage multiple active node.js versions

安裝:

  1. 使用官方提供的自動化安裝腳本
curl -o- <https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh> | bash
  1. 透過 oh-my-zsh 插件安裝

使用:

  • 安裝 Node.js 16
nvm install 16
  • 解除安裝 Node.js 16.14.0
nvm uninstall 16.14.0
  • 暫時切換到 Node.js 14
nvm use 14
  • 設定預設 Node.js 版本
nvm alias default 16
  • 從另一個版本重新安裝 Global Package
nvm reinstall-packages 16.14.0

其他使用方法請參考 https://github.com/nvm-sh/nvm


htop

終端機的「工作管理員」

Untitled

**安裝:**透過套件管理工具安裝 htop即可

sudo apt install htop

簡易使用說明:

  • F2: 設定 htop
  • F5: 切換清單 / 樹狀檢視
  • F9: 終止程式
  • F10: 離開 htop
  • H: 切換執行緒顯示(綠色的那幾行)

Nerd Font

Nerd font 是有名的字型模組,包含了許多圖示,可以在文字介面上擁有豐富的圖示,目前常見的等寬字型都有收錄。

Nerd Fonts – Iconic font aggregator, glyphs/icons collection, & fonts patcher

透過 oh-my-posh 自動化安裝

oh-my-posh 有提供安裝自行的指令,目前為 Beta 階段

oh-my-posh font install

<aside> ⚠️ 需使用系統管理員權限執行終端機,才能安裝字體

</aside>

此時會有字體選擇清單,選擇一個你習慣使用的字體,我的話會選 JetBrainsMono,按下 Enter 就會開始下載安裝

Untitled

自行安裝 Nerd Font

到以下連結下載您想要的字體

Nerd Fonts – Iconic font aggregator, glyphs/icons collection, & fonts patcher

Untitled

Windows 安裝方式

  • 解壓縮後安裝含 Nerd Font Complete Mono Windows Compatible 的字體安裝,如果有很多個,選其中一個(Regular)安裝即可
Untitled

Brew (Mac) 安裝方式:

  • 在終端機執行以下指令
brew tap homebrew/cask-fonts
brew install --cask font-<FONT NAME>-nerd-font

其中 <FONT NAME> 以字體的名字代替

Linux 安裝方式(以 Ubuntu / Debian 為例)

/usr/local/share/fonts/ 是系統字體路徑

~/.local/share/fonts/ 或 ~/.fonts 是目前使用者字體路徑

  1. 下載想要的字體 (下載按鈕的連結,以 JetBrains Mono 為例) wget <https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/JetBrainsMono.zip>
  2. 將下載的字體解壓縮到 ~/.fonts
mkdir ~/.fonts
unzip JetBrainsMono.zip -d ~/.fonts
  1. 將 Windows 專用的字體刪掉
cd ~/.fonts
rm *Windows*
cd ~
  1. 重新載入字體快取
fc-cache -fv

<aside> 💡 Arch Linux 使用者可以透過 ArchLinux User Repository(AUR) 安裝 nerd font

AUR (en) – Packages

</aside>

參考來源:

Install a nerd font on ubuntu


套用字體設定

Windows Terminal

  1. 開啟設定,選擇「預設值」設定檔或「PowerShell」設定檔(建議改「預設值」)
Untitled
  1. 進入外觀設定,將字體改成剛剛安裝的 Nerd Font (通常為 NF 結尾)後,並按下「儲存」
Untitled

Gnome Shell

  1. 按下右上角的選單按鈕,並選擇偏好設定
Untitled
  1. 選擇目前使用的設定檔,將「自訂字型」勾起來,並按一下右邊的按鈕
Untitled
  1. 選擇含「Nerd Font Mono」的字體後按下「選取」
Untitled

Konsole

<aside> ⚠️ 安裝字體後需先重新啟動 Konsole

</aside>

  1. 進入設定 > 編輯目前的設定檔
Untitled
  1. 選擇外觀,並按一下字型右邊的選擇按鈕
Untitled
  1. 選擇含「Nerd Font Mono」的字體後按下「確定」
Untitled

Visual Studio Code

  1. 開啟設定 Untitled
  2. 搜尋 terminal.integrated.fontFamily
Untitled
  1. 打入剛剛安裝的字體名稱
Untitled

<aside> 💡 設定完成後就可以回去設定 oh-my-poshpowerlevel10k

</aside>

訂閱研究文章

Get updates and learn from the best

More To Explore

Commitizen

前言: 現今軟體功能複雜與龐大,在開發過程中,不管單人開發還是多人協作,對所編寫的代碼與代碼版本管控都是必須的

NFC x Mifare

實作紀錄 readMifare readNdef 知識補充 手機NFC隱含攻擊弱點 掌握原理避免無線盜刷 MI

Scroll to Top