前置条件
-
安装PowerShell Core -
https://docs.microsoft.com/zh-cn/powershell/scripting/install/installing-powershell -
安装VS Code -
https://code.visualstudio.com/insiders/# -
推荐使用 Windows Terminal 终端工具效果更好.
安装美化工具
-
美化 PowerShell 需要安装如下模块,这里写出他们的文档和相关网站.
-
需要oh-my-posh,他的文档如下:
-
https://ohmyposh.dev/docs
-
以及posh-git
-
https://github.com/dahlbyk/posh-git
-
接下来以管理员身份打开 PowerShell, 执行
Install-Module oh-my-posh
Install-Module posh-git
Install-Module -Name PSReadLine -AllowPrerelease -Force
-
这里之所以要安装预览版 PSReadLine 是因为后续的 PredictionViewStyle 选项是 2.2 之后才支持的,而目前稳定版是 2.1。PowerShell Core 默认内置稳定版 PSReadLine, 等下个版本应该就不用手动安装 PSReadLine 了
-
配置 profile,执行
$profile
然后会显示 profile 文件所在路径, 一般是%UserProfile%DocumentsPowerShellMicrosoft.PowerShell_profile.ps1
-
然后执行
code $profile
(正式版 VSCode)或者code-insiders $profile
(预览版 VSCode)用 vsc 打开, 如果没有就会自动创建 -
内容如下:
Import-Module posh-git
Import-Module oh-my-posh
# 设置为 material 主题
Set-PoshPrompt -Theme material
Register-ArgumentCompleter -Native -CommandName dotnet -ScriptBlock {
param($commandName, $wordToComplete, $cursorPosition)
dotnet complete --position $cursorPosition "$wordToComplete" | ForEach-Object {
[CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
Set-PSReadLineKeyHandler -Key "Ctrl+f" -Function ForwardWord
Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete
Set-PSReadLineKeyHandler -Key "Ctrl+z" -Function Undo
Set-PSReadLineOption -PredictionSource History -PredictionViewStyle ListView
可以通过命令Get-PoshThemes
获取主题列表, 然后替换里边的 material 主题即可
效果如下,按上下键切换 自动提示列表来源于历史记录
原文始发于微信公众号(鱼丸的技术趴):PowerShell Core美化
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/117149.html