modules

modules #

常用模块介绍。

PSReadline #

提供改进的命令行编辑体验。

官网文档: https://learn.microsoft.com/zh-cn/powershell/module/psreadline/set-psreadlineoption?view=powershell-5.1#parameters

安装:

ps1
# PowerShell默认自带低版本PSReadLine,强制安装最新版本:
Install-Module PSReadLine -Force

配置:

ps1
#Import-Module PSReadLine
$PSReadLineOptions = @{
    # Simulate Bash or Emacs
    EditMode = "Emacs"
    # PredictionViewStyle = "ListView"
    HistoryNoDuplicates = $true
    HistorySearchCursorMovesToEnd = $true
    # AddToHistoryHandler = {
    #     Param([string]$line)
    #     if ($line -match "^git") {
    #         return $false
    #     } else {
    #         return $true
    #     }
    # }
}
Set-PSReadLineOption @PSReadLineOptions
Set-PSReadlineKeyHandler -Chord Tab -Function MenuComplete

常用操作:

ps1
# 显示历史记录文件路径
(Get-PSReadlineOption).HistorySavePath

# 编辑器打开历史记录文件
notepad (Get-PSReadlineOption).HistorySavePath

# 查看键位绑定
Get-PSReadLineKeyHandler

Posh-Git #

命令提示符添加Git仓库信息。

安装:

ps1
Install-Module Posh-Git -Scope CurrentUser

配置:

ps1
Import-Module Posh-Git

OhMyPosh #

命令提示符美化。

安装:

ps1
winget install JanDeDobbeleer.OhMyPosh

配置:

ps1
TODO
2024年8月6日