diff --git a/module/PowerShellEditorServices/Commands/PowerShellEditorServices.Commands.psd1 b/module/PowerShellEditorServices/Commands/PowerShellEditorServices.Commands.psd1 index 88e0e63da..dbbbea6a3 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 = @() @@ -86,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/module/PowerShellEditorServices/Commands/Public/CmdletInterface.ps1 b/module/PowerShellEditorServices/Commands/Public/CmdletInterface.ps1 index 131d0964f..83094c02a 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 } | % { + Get-ChildItem $FilePaths -File | ForEach-Object { $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..5e3f324f0 100644 --- a/src/PowerShellEditorServices/Session/RemoteFileManager.cs +++ b/src/PowerShellEditorServices/Session/RemoteFileManager.cs @@ -72,21 +72,27 @@ public class RemoteFileManager [string] $PSEditFunction ) - Register-EngineEvent -SourceIdentifier PSESRemoteSessionOpenFile {0} + Register-EngineEvent -SourceIdentifier PSESRemoteSessionOpenFile -Forward - 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') { - Remove-Item -Path 'function:\global:PSEdit' -Force + Remove-Item -Path 'function:\global:Open-EditorFile' -Force } - Get-EventSubscriber -SourceIdentifier PSESRemoteSessionOpenFile -EA Ignore | Remove-Event + if (Test-Path -Path 'alias:\psedit') + { + Remove-Item -Path 'alias:\psedit' -Force + } + + Get-EventSubscriber -SourceIdentifier PSESRemoteSessionOpenFile -EA Ignore | Unregister-Event "; private const string SetRemoteContentsScript = @"