feat: modularize powershell profile
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
using namespace System.Management.Automation
|
||||
using namespace System.Management.Automation.Language
|
||||
|
||||
Register-ArgumentCompleter -Native -CommandName winget -ScriptBlock {
|
||||
param($wordToComplete, $commandAst, $cursorPosition)
|
||||
[Console]::InputEncoding = [Console]::OutputEncoding = $OutputEncoding = [System.Text.Utf8Encoding]::new()
|
||||
$Local:word = $wordToComplete.Replace('"', '""')
|
||||
$Local:ast = $commandAst.ToString().Replace('"', '""')
|
||||
winget complete --word="$Local:word" --commandline "$Local:ast" --position $cursorPosition | ForEach-Object {
|
||||
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
|
||||
}
|
||||
}
|
||||
|
||||
# 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', $_)
|
||||
}
|
||||
}
|
||||
|
||||
Import-Module PSReadLine -ErrorAction SilentlyContinue
|
||||
if (Get-Command Set-PSReadLineOption -ErrorAction SilentlyContinue) {
|
||||
# Auto correct 'git cmt' to 'git commit'
|
||||
Set-PSReadLineOption -CommandValidationHandler {
|
||||
param([CommandAst]$CommandAst)
|
||||
|
||||
switch ($CommandAst.GetCommandName()) {
|
||||
'git' {
|
||||
$gitCmd = $CommandAst.CommandElements[1].Extent
|
||||
switch ($gitCmd.Text) {
|
||||
'cmt' {
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::Replace(
|
||||
$gitCmd.StartOffset, $gitCmd.EndOffset - $gitCmd.StartOffset, 'commit')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user