-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMicrosoft.Powershell_profile.ps1
81 lines (69 loc) · 3.14 KB
/
Microsoft.Powershell_profile.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Import necessary modules
Import-Module posh-git
# Set key handlers for PSReadLine
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete
# Initialize the dotnet cache if it doesn't exist
if ($null -eq $global:dotnetCompletionCache) {
$global:dotnetCompletionCache = @{}
}
# PowerShell parameter completion shim for the dotnet CLI
Register-ArgumentCompleter -Native -CommandName dotnet -ScriptBlock {
param($commandName, $wordToComplete, $cursorPosition)
$cacheKey = "$wordToComplete`:$cursorPosition"
if ($global:dotnetCompletionCache.ContainsKey($cacheKey)) {
$global:dotnetCompletionCache[$cacheKey] | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
} else {
try {
$runspace = [powershell]::Create().AddScript({
param($wordToComplete, $cursorPosition, $cacheKey)
$results = dotnet complete --position $cursorPosition "$wordToComplete"
$results | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
$global:dotnetCompletionCache[$cacheKey] = $results
return $results
}).AddArgument($wordToComplete).AddArgument($cursorPosition).AddArgument($cacheKey)
$runspace.Invoke()
$runspace.Dispose()
} catch {
Write-Error "Failed to complete dotnet command: $_"
}
}
}
# Initialize the winget cache if it doesn't exist
if ($null -eq $global:wingetCache) {
$global:wingetCache = @{}
}
# Windows Package Manager parameter completion shim for the winget CLI
Register-ArgumentCompleter -Native -CommandName winget -ScriptBlock {
param($wordToComplete, $commandAst, $cursorPosition)
# Simplified cache key based on input parameters
$cacheKey = "$wordToComplete|$cursorPosition"
# Return cached results if available
if ($global:wingetCache.ContainsKey($cacheKey)) {
return $global:wingetCache[$cacheKey]
}
try {
$runspace = [powershell]::Create().AddScript({
param($wordToComplete, $commandAst, $cursorPosition, $cacheKey)
$results = winget complete --word="$wordToComplete" --commandline "$commandAst" --position $cursorPosition | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
$global:wingetCache[$cacheKey] = $results
return $results
}).AddArgument($wordToComplete).AddArgument($commandAst).AddArgument($cursorPosition).AddArgument($cacheKey)
$results = $runspace.Invoke()
$runspace.Dispose()
return $results
} catch {
Write-Error "Failed to complete winget command: $_"
}
}
# Set aliases
Set-Alias -Name cat -Value bat
New-Alias -Name nvm -Value nvs
New-Alias -Name grep -Value rg