Last active
February 3, 2023 06:08
-
-
Save kkbruce/3cc8359a8587e4cdf389106f868f3410 to your computer and use it in GitHub Desktop.
設定PowerShell Core與WSL好看又實用的指令碼環境
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 新主機 | |
winget install Microsoft.WindowsTerminal | |
winget install Microsoft.PowerShell | |
# 安裝 oh-my-posh | |
# https://ohmyposh.dev/docs/migrating,不要再使用 install-Module 來安裝 | |
# Install-Module oh-my-posh -Scope CurrentUser -Force | |
winget install JanDeDobbeleer.OhMyPosh | |
# 安裝 Terminal-Icons 模組 | |
Install-Module -Name Terminal-Icons -Repository PSGallery -Force | |
# 安裝最新版 PSReadLine 模組 | |
Install-Module PSReadLine -AllowPrerelease -Force | |
# 安裝 Nerd Fonts 字型檔;手動安裝也行。 | |
Invoke-WebRequest -Uri "https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/CascadiaCode.zip" -OutFile CascadiaCode.zip | |
$tmpFolder = New-TemporaryFile | %{ rm $_; mkdir $_ } | |
Expand-Archive -LiteralPath CascadiaCode.zip -DestinationPath $tmpFolder | |
Remove-Item -Path .\CascadiaCode.zip | |
# https://www.powershellgallery.com/packages/PSWinGlue | |
#Install-Module -Name PSWinGlue -Force | |
#Install-Font -Scope User -Path $tmpFolder | |
explorer $tmpFolder | |
# 設定檔 | |
Invoke-WebRequest -Uri "https://gist.githubusercontent.com/shanselman/1f69b28bfcc4f7716e49eb5bb34d7b2c/raw/8e9c9a8736ff4e9e5a863c20833d614549ccbc32/ohmyposhv3-v2.json" -OutFile "~/.ohmyposhv3-v2.json" | |
# Profile 設定 | |
code $PROFILE | |
# Profile | |
Import-Module -Name Terminal-Icons | |
Import-Module oh-my-posh | |
oh-my-posh init pwsh --config "~/.ohmyposhv3-v2.json" | Invoke-Expression | |
if ($host.Name -eq 'ConsoleHost') | |
{ | |
Import-Module PSReadLine | |
} | |
Set-PSReadLineOption -PredictionSource History | |
Set-PSReadLineOption -PredictionViewStyle ListView | |
Set-PSReadLineOption -EditMode Windows | |
#Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward | |
#Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward | |
# PowerShell parameter completion shim for the dotnet CLI | |
Register-ArgumentCompleter -Native -CommandName dotnet -ScriptBlock { | |
param($commandName, $wordToComplete, $cursorPosition) | |
dotnet complete --position $cursorPosition "$wordToComplete" | ForEach-Object { | |
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) | |
} | |
} | |
Get-Command | Get-Random | Get-Help -Full | |
###### WSL 設定 | |
sudo wget https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/posh-linux-amd64 -O /usr/local/bin/oh-my-posh | |
sudo chmod +x /usr/local/bin/oh-my-posh | |
mkdir ~/.poshthemes | |
wget https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/themes.zip -O ~/.poshthemes/themes.zip | |
## sudo apt install unzip | |
unzip ~/.poshthemes/themes.zip -d ~/.poshthemes | |
chmod u+rw ~/.poshthemes/*.json | |
rm ~/.poshthemes/themes.zip | |
curl -s 'https://gist.githubusercontent.com/shanselman/1f69b28bfcc4f7716e49eb5bb34d7b2c/raw/8e9c9a8736ff4e9e5a863c20833d614549ccbc32/ohmyposhv3-v2.json' -o ~/.poshthemes/ohmyposhv3-v2.json | |
## 加入到 ~/.bashrc 啟動設定檔中 | |
eval "$(oh-my-posh --init --shell bash --config ~/.poshthemes/ohmyposhv3-v2.json)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment