-
Notifications
You must be signed in to change notification settings - Fork 228
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
change psedit to Open-EditorFile and alias psedit to it #609
Conversation
@@ -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 = @() |
There was a problem hiding this comment.
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. :-)
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
Remove-Item -Path 'function:\global:Open-EditorFile' -Force | ||
} | ||
|
||
if (Get-Alias psedit) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is unlikely that psedit
wouldn't be defined but if it isn't this will generate a non-term error. Maybe use Test-Path alias:\psedit
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
|
||
if (Get-Alias psedit) | ||
{ | ||
Remove-Alias psedit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I believe Remove-Alias
was added for PS Core. In my Win PS 5.1 that command doesn't exist.
remove-alias : The term 'remove-alias' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Try Remove-Item alias:\psedit
instead. That should work across all versions of PS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
@@ -77,11 +77,13 @@ function Unregister-EditorCommand { | |||
} | |||
} | |||
|
|||
function psedit { | |||
function Open-EditorFile { | |||
param([Parameter(Mandatory=$true)]$FilePaths) | |||
|
|||
dir $FilePaths | where { !$_.PSIsContainer } | % { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While we're modifying this function, it may be a good time to replace the aliases and use the -File
parameter (added in PSv3)
Get-ChildItem $FilePaths -File | ForEach-Object {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. PSSA should have flagged these inside VSCode. Hmm....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It did :) I just missed it. Fixed this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with Keith's recommendations. Other than that, looks good!
|
||
if (Test-Path -Path 'alias:\psedit') | ||
{ | ||
Remove-Item -Path 'alias:\psedit' -Force | ||
} | ||
|
||
Get-EventSubscriber -SourceIdentifier PSESRemoteSessionOpenFile -EA Ignore | Remove-Event |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR may not be the right place to change this, but are we sure Remove-Event
actually works here? I feel like either that's supposed to be Unregister-Event
or Get-EventSubscriber
is supposed to be Get-Event
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly I'm not sure, I stole this code from the ISE codebase :) If you think there's an actual problem here we should definitely fix it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep
Register-EngineEvent -SourceIdentifier PSESRemoteSessionOpenFile -Forward
Get-EventSubscriber -SourceIdentifier PSESRemoteSessionOpenFile | Remove-Event
# Remove-Event : The input object cannot be bound to any parameters for the command either because the command does not
# take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
# At line:1 char:65
# + ... ntSubscriber -SourceIdentifier PSESRemoteSessionOpenFile | Remove-Event
# + ~~~~~~~~~~~~
# + CategoryInfo : InvalidArgument: (System.Manageme...EventSubscriber:PSObject) [Remove-Event], ParameterB
# indingException
# + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Commands.RemoveEventCommand
@tylerl0706 Remove-Event
should be Unregister-Event
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right :)
PS > Get-EventSubscriber | Remove-Event
Remove-Event : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
At line:1 char:23
+ Get-EventSubscriber | Remove-Event
+ ~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (System.Manageme...EventSubscriber:PSObject) [Remove-Event], ParameterBindingException
+ FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Commands.RemoveEventCommand
PS > Get-EventSubscriber | Unregister-Event
PS >
I'll change it to Unregister-Event
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done :)
@@ -74,16 +74,22 @@ public class RemoteFileManager | |||
|
|||
Register-EngineEvent -SourceIdentifier PSESRemoteSessionOpenFile {0} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to pollute your PR, but I found another one. The input for {0}
is passed on line 494. It either passes string.Empty
for local runspaces or -Forward
for remote runspaces. Register-EngineEvent
requires either the -Forward
switch or the -Action
script block parameter.
Register-EngineEvent -SourceIdentifier PSESRemoteSessionOpenFile
# Register-EngineEvent : Action must be specified for non-forwarded events.
# At line:1 char:1
# + Register-EngineEvent -SourceIdentifier PSESRemoteSessionOpenFile
# + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# + CategoryInfo : InvalidArgument: (:) [Register-EngineEvent], ArgumentException
# + FullyQualifiedErrorId : ACTION_MANDATORY_FOR_LOCAL,Microsoft.PowerShell.Commands.RegisterEngineEventCommand
I'm thinking we probably just need to always pass -Forward
. This may explain psedit
not working properly with some session types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may explain psedit not working properly with some session types.
which session types? I haven't had any issue with WinRM, SSH, or PowerShell Direct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That said, I can change:
Register-EngineEvent -SourceIdentifier PSESRemoteSessionOpenFile {0}
to
Register-EngineEvent -SourceIdentifier PSESRemoteSessionOpenFile -Forward
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tylerl0706 ah right, the condition is probably never hit. It should still be changed at some point, but I doubt it actually affects anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-Forward
added :)
@@ -77,7 +77,8 @@ FunctionsToExport = @('Register-EditorCommand', | |||
'Out-CurrentFile', | |||
'Join-ScriptExtent', | |||
'Test-ScriptExtent', | |||
'psedit') | |||
'psedit', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an AliasesToExport
field down below to put psedit
in. That is where it should go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doh! Fixed now.
This works both in local and remote sessions.
psedit became Open-EditorFile
and psedit aliases Open-EditorFile
Resolves #528