Skip to content

Commit 24307e7

Browse files
geranedaviwil
authored andcommitted
Add Editor Commands for opening Profiles (#254)
* Add Editor Commands for opening Profiles This change adds the following built-in Editor Commands - PowerShellEditorServices.OpenEditorProfile: Opens the current Editor's profile. Uses $profile so should work when other Editors use PSES. - PowerShellEditorServices.OpenProfileList: Prompts user with a list of Profiles to open. * Make Current editor default choice This change makes the is for PowerShellEditorServices.OpenProfileList Editor Command. It makes the default first selection the current Editor and filters out any duplicates. Should also account for any new profiles other Editors might add.
1 parent d00ed40 commit 24307e7

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Register-EditorCommand `
2+
-Name 'PowerShellEditorServices.OpenEditorProfile' `
3+
-DisplayName 'Open Editor Profile' `
4+
-SuppressOutput `
5+
-ScriptBlock {
6+
param([Microsoft.PowerShell.EditorServices.Extensions.EditorContext]$context)
7+
If (!(Test-Path -Path $Profile)) { New-Item -Path $Profile -ItemType File }
8+
$psEditor.Workspace.OpenFile($Profile)
9+
}
10+
11+
Register-EditorCommand `
12+
-Name 'PowerShellEditorServices.OpenProfileList' `
13+
-DisplayName 'Open Profile from List (Current User)' `
14+
-SuppressOutput `
15+
-ScriptBlock {
16+
param([Microsoft.PowerShell.EditorServices.Extensions.EditorContext]$context)
17+
18+
$Current = Split-Path -Path $profile -Leaf
19+
$List = @($Current,'Microsoft.VSCode_profile.ps1','Microsoft.PowerShell_profile.ps1','Microsoft.PowerShellISE_profile.ps1','Profile.ps1') | Select-Object -Unique
20+
$Choices = [System.Management.Automation.Host.ChoiceDescription[]] @($List)
21+
$Selection = $host.ui.PromptForChoice('Please Select a Profile', '(Current User)', $choices,'0')
22+
$Name = $List[$Selection]
23+
24+
$ProfileDir = Split-Path $Profile -Parent
25+
$ProfileName = Join-Path -Path $ProfileDir -ChildPath $Name
26+
27+
If (!(Test-Path -Path $ProfileName)) { New-Item -Path $ProfileName -ItemType File }
28+
29+
$psEditor.Workspace.OpenFile($ProfileName)
30+
}

0 commit comments

Comments
 (0)