-
Notifications
You must be signed in to change notification settings - Fork 234
change psedit to Open-EditorFile and alias psedit to it #609
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 Get-ChildItem $FilePaths -File | ForEach-Object { There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. It did :) I just missed it. Fixed this! |
||
$psEditor.Workspace.OpenFile($_.FullName) | ||
} | ||
} | ||
Export-ModuleMember -Function psedit | ||
Set-Alias psedit Open-EditorFile -Scope Global | ||
|
||
Export-ModuleMember -Function Open-EditorFile |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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 commentThe reason will be displayed to describe this comment to others. Learn more. That said, I can change:
to
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is unlikely that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed! |
||
{ | ||
Remove-Alias psedit | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, I believe
Try There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed! |
||
} | ||
|
||
Get-EventSubscriber -SourceIdentifier PSESRemoteSessionOpenFile -EA Ignore | Remove-Event | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right :)
I'll change it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done :) |
||
|
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!