-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMicrosoft.PowerShell_profile.ps1
125 lines (90 loc) · 3.59 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
Import-Module -Name Terminal-Icons
#Set-PoshPrompt -Theme free-ukraine
# Adjust path to profile according to your theme file location
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH/sitecore.omp.json" | Invoke-Expression
# Add PSReadLine
# https://github.com/PowerShell/PSReadLine
# https://devblogs.microsoft.com/powershell/announcing-psreadline-2-1-with-predictive-intellisense/
# https://docs.microsoft.com/en-us/powershell/module/psreadline/set-psreadlineoption?view=powershell-7.2
#--------------------
Import-Module PSReadLine
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -PredictionViewStyle ListView
Set-PSReadLineOption -EditMode Windows
# Custom styling of the PSReadLine ListView
Set-PSReadLineOption -Colors @{
ListPrediction = '#333378'
Emphasis = '#02999A'
}
#Get-PSReadLineOption
#Set-PSReadLineOption -Colors @{
# ListPredictionColor = 'Blue'
# ListPredictionSelectedColor = 'Purple'
# Command = 'Magenta'
# Comment = ''
# ContinuationPrompt = ''
# DefaultToken = ''
# Emphasis = ''
# Error = ''
# InlinePrediction = ''
# Keyword = ''
# ListPrediction = ''
# ListPredictionSelected = ''
# Selection = ''
# String = ''
# Number = 'DarkGray'
# Member = 'DarkGray'
# Operator = 'DarkGray'
# Type = 'DarkGray'
# Variable = 'DarkGreen'
# Parameter = 'DarkGreen'
# ContinuationPrompt = 'DarkGray'
# Default = 'DarkGray'
#}
# Add support for dotnet suggest shell start
#-------------------------------------------
function Add-Autocomplete {
param (
[string[]] $arguments,
[string[]] $commandName,
[int] $cursorPosition,
[System.Management.Automation.Language.CommandAst] $commandAst
)
$firstELement = $commandAst.CommandElements[0];
$commandToExecute = "$firstELement $commandName [suggest:$cursorPosition] ""$arguments"""
$listOfSuggestions = Invoke-Expression $commandToExecute
$lastArgument = $arguments.Split(" ", [System.StringSplitOptions]::RemoveEmptyEntries) | Select-Object -Last 1
$resultArray = @();
if ($lastArgument) {
$listOfSuggestions | ForEach-Object {
if ($_.StartsWith($lastArgument)) {
$resultArray += $_
}
}
}
if ($resultArray.Count -eq 0) {
$resultArray = $listOfSuggestions
}
$resultArray | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
# local Tool autocomplete
Register-ArgumentCompleter -Native -CommandName "dotnet" -ScriptBlock {
param($wordToComplete, $commandAst, $cursorPosition)
$arguments = $commandAst.Extent.ToString().Replace('"', '\"')
$commandName = "sitecore"
if ($arguments.Contains($commandName)) {
Add-Autocomplete -arguments $arguments -commandName $commandName -commandAst $commandAst -cursorPosition $cursorPosition
}
# Root command autocomplete
if ($commandName.StartsWith($commandAst.CommandElements[1])) {
[System.Management.Automation.CompletionResult]::new($commandName, $commandName, 'ParameterValue', $commandName)
}
}
# Global Tool autocomplete
Register-ArgumentCompleter -Native -CommandName "sitecore" -ScriptBlock {
param($wordToComplete, $commandAst, $cursorPosition)
$arguments = $commandAst.Extent.ToString().Replace('"', '\"')
Add-Autocomplete -arguments $arguments -commandAst $commandAst -cursorPosition $cursorPosition
}