Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change psedit to Open-EditorFile and alias psedit to it #609

Merged
merged 4 commits into from
Jan 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 = @()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be an entry to export psedit as an alias? I guess for this module we don't need to worry about module auto-loading (since it is pre-loaded into PSIC). Still, somehow feels better to declare everything in the manifest. :-)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting! didn't know you needed to list aliases in FunctionsToExport.

Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

Expand All @@ -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 = @()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 12 additions & 6 deletions src/PowerShellEditorServices/Session/RemoteFileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = @"
Expand Down