Last active
December 25, 2025 01:01
-
-
Save dongfg/2808f8388660ef70d96a0618b25ab594 to your computer and use it in GitHub Desktop.
[PowerShell Profile] Save file to $PROFILE
This file contains hidden or 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
| function Find-Command($cmdname) { | |
| return [bool](Get-Command -Name $cmdname -ErrorAction SilentlyContinue) | |
| } | |
| function Download-FileIfNotExists { | |
| param ( | |
| [string]$LocalFilePath, | |
| [string]$RemoteUrl | |
| ) | |
| if (-not (Test-Path -Path $LocalFilePath -PathType Leaf)) { | |
| $localDirectory = Split-Path -Path $LocalFilePath -Parent | |
| if (-not (Test-Path -Path $localDirectory)) { | |
| New-Item -Path $localDirectory -ItemType Directory -Force | Out-Null | |
| } | |
| Invoke-WebRequest -Uri $RemoteUrl -OutFile $LocalFilePath -UserAgent "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36" -UseBasicParsing | |
| } | |
| } | |
| # Alias | |
| Set-Alias ll Get-ChildItem | |
| # Git Alias | |
| if (Find-Command git) { | |
| function Get-GitStatus { git status } | |
| Set-Alias gst Get-GitStatus | |
| } | |
| # Oh My Posh | |
| # https://ohmyposh.dev/ | |
| if (Find-Command oh-my-posh) { | |
| Download-FileIfNotExists ~/Documents/PowerShell/themes/velvet.omp.json https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/refs/heads/main/themes/velvet.omp.json | |
| oh-my-posh init pwsh --config ~/Documents/PowerShell/themes/velvet.omp.json | Invoke-Expression | |
| } |
This file contains hidden or 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
| # OhMyPosh | |
| winget install JanDeDobbeleer.OhMyPosh --source winget | |
| Write-Host "OhMyPosh 已安装" | |
| # OhMyPosh font install | |
| pwsh -Command "oh-my-posh font install meslo" | |
| Write-Host "OhMyPosh 字体安装" | |
| # OhMyPosh font config | |
| $wtConfigDir = Join-Path -Path $env:LOCALAPPDATA -ChildPath "Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState" | |
| $settingsJsonPath = Join-Path -Path $wtConfigDir -ChildPath "settings.json" | |
| # 验证文件是否存在 | |
| if (-not (Test-Path -Path $settingsJsonPath -PathType Leaf)) { | |
| Write-Error "未找到 Windows Terminal 的 settings.json 文件,路径:$settingsJsonPath" | |
| exit 1 | |
| } | |
| $jsonContent = Get-Content -Path $settingsJsonPath -Raw -Encoding UTF8 | |
| $wtSettings = $jsonContent | ConvertFrom-Json | |
| # 确保 profiles 和 defaults 层级存在,避免报错 | |
| if (-not $wtSettings.profiles) { | |
| $wtSettings | Add-Member -MemberType NoteProperty -Name "profiles" -Value ([PSCustomObject]@{}) | |
| } | |
| if (-not $wtSettings.profiles.defaults) { | |
| $wtSettings.profiles | Add-Member -MemberType NoteProperty -Name "defaults" -Value ([PSCustomObject]@{}) | |
| } | |
| # 添加/覆盖 font 属性 | |
| $fontConfig = [PSCustomObject]@{ | |
| face = "MesloLGM Nerd Font" | |
| } | |
| $wtSettings.profiles.defaults | Add-Member -MemberType NoteProperty -Name "font" -Value $fontConfig -Force | |
| # 将修改后的对象序列化回 JSON 并保存(保留格式化和编码) | |
| $updatedJson = $wtSettings | ConvertTo-Json -Depth 10 | |
| $updatedJson | Set-Content -Path $settingsJsonPath -Encoding UTF8 -Force | |
| Write-Host "Windows Terminal 字体设置成功" | |
| Write-Host "开始安装 Git" | |
| winget install Git.Git --source winget --interactive | |
| winget install GitTower.GitFlowNext --source winget |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.