5.3 KiB
安装 PowerShell
官方安装教程
查找 PowerShell 版本
winget search Microsoft.PowerShell
Name Id Version Source
---------------------------------------------------------------
PowerShell Microsoft.PowerShell 7.5.1.0 winget
PowerShell Preview Microsoft.PowerShell.Preview 7.6.0.4 winget
进行安装
winget install --id Microsoft.PowerShell --source winget
winget install --id Microsoft.PowerShell.Preview --source winget
更新操作
winget upgrade Microsoft.PowerShell
配置 PowerShell
首次在系统上安装 PowerShell 时,配置文件脚本文件和它们所属的目录不存在。 以下命令创建“当前用户,当前主机”配置文件脚本文件(如果不存在)。
if (!(Test-Path $PROFILE)) { New-Item -Type File -Path $PROFILE -Force }
添加个性化设置
function desk { Set-Location "C:\Users\docke\Desktop" }
function gitl { git log --oneline --graph --decorate }
function ep { code $PROFILE }
function hosts { notepad C:\Windows\System32\drivers\etc\hosts }
function vim { nvim $args }
Set-PSReadLineOption -PredictionSource History, Plugin
Set-PSReadLineOption -PredictionViewStyle ListView
Set-PSReadLineOption -EditMode Windows
Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete
安装 Windows 终端
官方安装教程
https://learn.microsoft.com/zh-cn/windows/terminal/install
根据页面自行定制化设置即可,需确认好终端已将前边最新 PowerShell 设置为默认值。
安装 Nerd Fonts 字体
官网: https://www.nerdfonts.com/
Nerd Fonts 是一个为开发者量身定制的字体资源网站,通过将编程字体与图标字体结合,提供了一种功能强大且美观的方式来优化开发环境。无论是提升终端的视觉效果,还是增强代码的可读性和个性化,它都是一个非常有价值的工具。如果你是程序员或终端用户,这个网站值得一试。
其中我个人比较喜欢使用 JetBrainsMono Nerd Font。
安装 Oh My Posh
官方安装教程
推荐 winget 安装。
安装后在 PowerShell 配置文件中增加启动项,这里使用了自带的 jandedobbeleer 主题,这也是作者自己的主题。
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH/jandedobbeleer.omp.json" | Invoke-Expression
创建或修改 $PROFILE 文件后,需要重载它以应用更改。运行以下命令:
. $PROFILE
Oh My Posh 同样支持使用远程配置(但个人实测会有卡顿),本地配置会更加流畅。
个人配置
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"console_title_template": "{{ .Shell }} in {{ .Folder }}",
"final_space": true,
"version": 3,
"transient_prompt": {
"background": "transparent",
"foreground": "#ffffff",
"template": "{{ .Shell }}> "
},
"blocks": [
{
"type": "prompt",
"alignment": "left",
"segments": [
{
"type": "path",
"style": "diamond",
"leading_diamond": "\ue0b6",
"trailing_diamond": "\ue0b0",
"foreground": "#ffffff",
"background": "#ff479c",
"properties": {
"folder_separator_icon": " \ue0b1 ",
"home_icon": "~",
"style": "unique"
},
"template": " \uea83 {{ .Path }} "
},
{
"type": "executiontime",
"style": "plain",
"foreground": "#ffffff",
"background": "#83769c",
"properties": {
"always_enabled": true
},
"template": "<transparent>\ue0b0</> \ueba2 {{ .FormattedMs }}\u2800"
},
{
"type": "status",
"style": "diamond",
"trailing_diamond": "\ue0b4",
"foreground": "#ffffff",
"background": "#00897b",
"background_templates": ["{{ if gt .Code 0 }}#e91e63{{ end }}"],
"properties": {
"always_enabled": true
},
"template": "<parentBackground>\ue0b0</> \ue23a "
}
]
},
{
"type": "rprompt",
"segments": [
{
"type": "sysinfo",
"style": "plain",
"foreground": "#ffffff",
"template": "\uefc5 {{ round .PhysicalPercentUsed .Precision}}%"
}
]
}
]
}
安装 Scoop
Scoop 是一款适用于 Windows 的命令行包管理器,类似于 Linux 上的 apt 或 macOS 上的 Homebrew。它可以帮助用户快速安装和管理软件,尤其适合开发者或喜欢命令行操作的用户。
主要参考此仓库教程: https://github.com/ScoopInstaller/Install
进行高级安装,可以下载安装程序并手动执行它,并附带参数。
irm get.scoop.sh -outfile 'install.ps1'
可以将 Scoop 安装到自定义目录,配置 Scoop 将全局程序安装到自定义目录,并在安装过程中绕过系统代理。
.\install.ps1 -ScoopDir 'D:\Applications\Scoop' -ScoopGlobalDir 'F:\GlobalScoopApps' -NoProxy