設定 windows 開發環境

嘗試一下不使用 WSL2,直接在 Windows 上設定開發環境。

安裝 winget

Winget 為 Windows 系統上面的套件管理工具,類似於 Linux 上面的 aptyum

可以從 Windows Store 安裝,搜尋「應用程式安裝程式」並下載即可。

設定 SSH

Windows 11 內建有 OpenSSH,但 SSH Agent 並沒有啟動,可以設定開機自動啟動。

# 預設 ssh-agent 是關閉的,我們可以設定開機自動啟動
# 記得使用系統管理員權限執行
Get-Service ssh-agent | Set-Service -StartupType Automatic

# 請動 ssh-agent
Start-Service ssh-agent

# 下方指令確認 ssh-agent 是否啟動
Get-Service ssh-agent

# 將私鑰加入 ssh-agent
ssh-add $env:USERPROFILE\.ssh\id_ed25519

設定 Git

可以使用 winget 安裝 Git。

winget install -e -id Git.Git

-e 表示安裝最新的穩定版本,-id 表示安裝指定的套件。

初始設定。

git config --global user.name "Allen"
git config --global user.email "allen@email.com"

因為 Windows OS 預設使用 CRLF 當作換行 (End of Line, EOL), 在使用 git clone 時,會自動將檔案轉換成 CRLF 格式, 如果你不喜歡的話,記得在 Git 的 global 設定中要將 core.autocrlf 設定為 false

git config --global core.autocrlf false
git config --global core.eol lf

設定 Windows Terminal

在設定「互動」底下,將「自動將選取項目複製到剪貼簿」勾選。

設定 VS Code

VS Code 可以在 Microsoft Store 安裝,搜尋「Visual Studio Code」並下載即可。

設定 oh my posh

覺得 Windows Terminal 的介面太醜了嗎?可以使用 oh my posh 來美化介面。

可以在 Microsoft Store 安裝,搜尋「oh my posh」並下載即可。

或是使用 winget 安裝。

winget install JanDeDobbeleer.OhMyPosh

安裝完成之後先生成一個 powershell 的 profile 設定檔案。

new-item -type file -path $profile -force

使用 vscode 編輯 profile 檔案,並加入下方內容。

oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\paradox.omp.json" | Invoke-Expression

這個 profile 類似 linux 的 .bashrc 與 .zshrc,可以在開啟 powershell 時自動執行。

你也可以這裡設定 alias,例如 New-Alias -Name "tf" terraform

其中的 paradox 為 oh my posh 的主題,可以從網站上挑選自己喜歡的自行更換。

參考資料


This site uses Just the Docs, a documentation theme for Jekyll.