From ea965c2f733cd6f293682b925958dfa249e53b15 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Thu, 11 Jan 2018 20:22:39 -0800 Subject: [PATCH 1/4] change psedit to Open-EditorFile and alias psedit to it --- .../PowerShellEditorServices.Commands.psd1 | 2 +- .../Commands/Public/CmdletInterface.ps1 | 6 ++++-- .../Session/RemoteFileManager.cs | 14 ++++++++++---- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/module/PowerShellEditorServices/Commands/PowerShellEditorServices.Commands.psd1 b/module/PowerShellEditorServices/Commands/PowerShellEditorServices.Commands.psd1 index 88e0e63da..7985ec035 100644 --- a/module/PowerShellEditorServices/Commands/PowerShellEditorServices.Commands.psd1 +++ b/module/PowerShellEditorServices/Commands/PowerShellEditorServices.Commands.psd1 @@ -77,7 +77,7 @@ FunctionsToExport = @('Register-EditorCommand', 'Out-CurrentFile', 'Join-ScriptExtent', 'Test-ScriptExtent', - 'psedit') + 'Open-EditorFile') # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. CmdletsToExport = @() diff --git a/module/PowerShellEditorServices/Commands/Public/CmdletInterface.ps1 b/module/PowerShellEditorServices/Commands/Public/CmdletInterface.ps1 index 131d0964f..ae0be70f7 100644 --- a/module/PowerShellEditorServices/Commands/Public/CmdletInterface.ps1 +++ b/module/PowerShellEditorServices/Commands/Public/CmdletInterface.ps1 @@ -77,11 +77,13 @@ function Unregister-EditorCommand { } } -function psedit { +function Open-EditorFile { param([Parameter(Mandatory=$true)]$FilePaths) dir $FilePaths | where { !$_.PSIsContainer } | % { $psEditor.Workspace.OpenFile($_.FullName) } } -Export-ModuleMember -Function psedit +Set-Alias psedit Open-EditorFile -Scope Global + +Export-ModuleMember -Function Open-EditorFile diff --git a/src/PowerShellEditorServices/Session/RemoteFileManager.cs b/src/PowerShellEditorServices/Session/RemoteFileManager.cs index c36582fab..b418ec32a 100644 --- a/src/PowerShellEditorServices/Session/RemoteFileManager.cs +++ b/src/PowerShellEditorServices/Session/RemoteFileManager.cs @@ -74,16 +74,22 @@ public class RemoteFileManager Register-EngineEvent -SourceIdentifier PSESRemoteSessionOpenFile {0} - if ((Test-Path -Path 'function:\global:PSEdit') -eq $false) + if ((Test-Path -Path 'function:\global:Open-EditorFile') -eq $false) {{ - Set-Item -Path 'function:\global:PSEdit' -Value $PSEditFunction + Set-Item -Path 'function:\global:Open-EditorFile' -Value $PSEditFunction + Set-Alias psedit Open-EditorFile -Scope Global }} "; private const string RemovePSEditFunctionScript = @" - if ((Test-Path -Path 'function:\global:PSEdit') -eq $true) + if ((Test-Path -Path 'function:\global:Open-EditorFile') -eq $true) { - Remove-Item -Path 'function:\global:PSEdit' -Force + Remove-Item -Path 'function:\global:Open-EditorFile' -Force + } + + if (Get-Alias psedit) + { + Remove-Alias psedit } Get-EventSubscriber -SourceIdentifier PSESRemoteSessionOpenFile -EA Ignore | Remove-Event From efaf12963465ca97d6c63e34141146fa6687d79c Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Fri, 12 Jan 2018 11:42:48 -0800 Subject: [PATCH 2/4] address misc feedback --- .../Commands/PowerShellEditorServices.Commands.psd1 | 1 + .../Commands/Public/CmdletInterface.ps1 | 2 +- src/PowerShellEditorServices/Session/RemoteFileManager.cs | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/module/PowerShellEditorServices/Commands/PowerShellEditorServices.Commands.psd1 b/module/PowerShellEditorServices/Commands/PowerShellEditorServices.Commands.psd1 index 7985ec035..dbd4a8187 100644 --- a/module/PowerShellEditorServices/Commands/PowerShellEditorServices.Commands.psd1 +++ b/module/PowerShellEditorServices/Commands/PowerShellEditorServices.Commands.psd1 @@ -77,6 +77,7 @@ FunctionsToExport = @('Register-EditorCommand', 'Out-CurrentFile', 'Join-ScriptExtent', 'Test-ScriptExtent', + 'psedit', 'Open-EditorFile') # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. diff --git a/module/PowerShellEditorServices/Commands/Public/CmdletInterface.ps1 b/module/PowerShellEditorServices/Commands/Public/CmdletInterface.ps1 index ae0be70f7..83094c02a 100644 --- a/module/PowerShellEditorServices/Commands/Public/CmdletInterface.ps1 +++ b/module/PowerShellEditorServices/Commands/Public/CmdletInterface.ps1 @@ -80,7 +80,7 @@ function Unregister-EditorCommand { function Open-EditorFile { param([Parameter(Mandatory=$true)]$FilePaths) - dir $FilePaths | where { !$_.PSIsContainer } | % { + Get-ChildItem $FilePaths -File | ForEach-Object { $psEditor.Workspace.OpenFile($_.FullName) } } diff --git a/src/PowerShellEditorServices/Session/RemoteFileManager.cs b/src/PowerShellEditorServices/Session/RemoteFileManager.cs index b418ec32a..0a0bd6898 100644 --- a/src/PowerShellEditorServices/Session/RemoteFileManager.cs +++ b/src/PowerShellEditorServices/Session/RemoteFileManager.cs @@ -82,14 +82,14 @@ public class RemoteFileManager "; private const string RemovePSEditFunctionScript = @" - if ((Test-Path -Path 'function:\global:Open-EditorFile') -eq $true) + if (Test-Path -Path 'function:\global:Open-EditorFile') { Remove-Item -Path 'function:\global:Open-EditorFile' -Force } - if (Get-Alias psedit) + if (Test-Path -Path 'alias:\psedit') { - Remove-Alias psedit + Remove-Item -Path 'alias:\psedit' -Force } Get-EventSubscriber -SourceIdentifier PSESRemoteSessionOpenFile -EA Ignore | Remove-Event From c447d84c2f4bac26a412f6fde11c23e19ed219ad Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Fri, 12 Jan 2018 13:10:54 -0800 Subject: [PATCH 3/4] remove -> unregister --- src/PowerShellEditorServices/Session/RemoteFileManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PowerShellEditorServices/Session/RemoteFileManager.cs b/src/PowerShellEditorServices/Session/RemoteFileManager.cs index 0a0bd6898..63a258ba6 100644 --- a/src/PowerShellEditorServices/Session/RemoteFileManager.cs +++ b/src/PowerShellEditorServices/Session/RemoteFileManager.cs @@ -92,7 +92,7 @@ public class RemoteFileManager Remove-Item -Path 'alias:\psedit' -Force } - Get-EventSubscriber -SourceIdentifier PSESRemoteSessionOpenFile -EA Ignore | Remove-Event + Get-EventSubscriber -SourceIdentifier PSESRemoteSessionOpenFile -EA Ignore | Unregister-Event "; private const string SetRemoteContentsScript = @" From e4516c2d4783a615b25d3b7706fff133e2b8b624 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Fri, 12 Jan 2018 13:45:24 -0800 Subject: [PATCH 4/4] misc feedback --- .../Commands/PowerShellEditorServices.Commands.psd1 | 3 +-- src/PowerShellEditorServices/Session/RemoteFileManager.cs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/module/PowerShellEditorServices/Commands/PowerShellEditorServices.Commands.psd1 b/module/PowerShellEditorServices/Commands/PowerShellEditorServices.Commands.psd1 index dbd4a8187..dbbbea6a3 100644 --- a/module/PowerShellEditorServices/Commands/PowerShellEditorServices.Commands.psd1 +++ b/module/PowerShellEditorServices/Commands/PowerShellEditorServices.Commands.psd1 @@ -77,7 +77,6 @@ FunctionsToExport = @('Register-EditorCommand', 'Out-CurrentFile', 'Join-ScriptExtent', 'Test-ScriptExtent', - 'psedit', 'Open-EditorFile') # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. @@ -87,7 +86,7 @@ CmdletsToExport = @() VariablesToExport = @() # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. -AliasesToExport = @() +AliasesToExport = @('psedit') # DSC resources to export from this module # DscResourcesToExport = @() diff --git a/src/PowerShellEditorServices/Session/RemoteFileManager.cs b/src/PowerShellEditorServices/Session/RemoteFileManager.cs index 63a258ba6..5e3f324f0 100644 --- a/src/PowerShellEditorServices/Session/RemoteFileManager.cs +++ b/src/PowerShellEditorServices/Session/RemoteFileManager.cs @@ -72,7 +72,7 @@ public class RemoteFileManager [string] $PSEditFunction ) - Register-EngineEvent -SourceIdentifier PSESRemoteSessionOpenFile {0} + Register-EngineEvent -SourceIdentifier PSESRemoteSessionOpenFile -Forward if ((Test-Path -Path 'function:\global:Open-EditorFile') -eq $false) {{