Skip to content

Enable piping text to psedit to open a new untitled buffer #414

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

Closed
daviwil opened this issue Apr 3, 2017 · 18 comments
Closed

Enable piping text to psedit to open a new untitled buffer #414

daviwil opened this issue Apr 3, 2017 · 18 comments
Assignees
Labels
Area-Extension Terminal Issue-Enhancement A feature request (enhancement).
Milestone

Comments

@daviwil
Copy link
Contributor

daviwil commented Apr 3, 2017

It should be possible to pipe text from an arbitrary command into psedit to open a new untitled file buffer. For example:

Get-Process | psedit

@daviwil daviwil added the Issue-Enhancement A feature request (enhancement). label Apr 3, 2017
@daviwil daviwil modified the milestones: 1.0, April 2017 Apr 3, 2017
@daviwil daviwil modified the milestones: June 2017, Backlog Oct 27, 2017
@TylerLeonhardt
Copy link
Member

It would be cool if we could get this in 1.6.0. I'd love to see if I could get this working.

@TylerLeonhardt TylerLeonhardt modified the milestones: Backlog, 1.6.0 Jan 12, 2018
@daviwil
Copy link
Contributor Author

daviwil commented Jan 12, 2018

This would definitely fit with a New-EditorFile cmdlet. Could have an optional pipeline param that accepts a string with the new file contents.

@TylerLeonhardt
Copy link
Member

That'd be great!

@TylerLeonhardt
Copy link
Member

Now that we've changed psedit to Open-EditorFile and want to add a New-EditorFile maybe we should consider creating a PowerShell module that EditorServices can import into it's session rather than calling the script block here:
https://github.com/PowerShell/PowerShellEditorServices/blob/master/src/PowerShellEditorServices/Session/RemoteFileManager.cs#L39-L96

@TylerLeonhardt
Copy link
Member

Open-EditorFile
New-EditorFile
Get-EditorFile
Close-EditorFile
Delete-EditorFile
Rename-EditorFile

@rkeithhill
Copy link
Contributor

From a maintenance point of view, it would be much nicer to edit those functions as PowerShell script vs C# strings. :-) Although, would we ship the module only with PSES? Would there be any need to put it on PSGallery?

@TylerLeonhardt
Copy link
Member

@rkeithhill even if we only ship it with PSES, it's probably still cleaner to pull the strings out into it's own PowerShell script.

That said, it could go on the gallery and then brought in for a release. That way we could separate it into its own repo.

I wonder how testing that module would work. 🤔

@SeeminglyScience
Copy link
Collaborator

I feel like I'm missing something. Those strings are just implementation detail for creating/cleaning up the function that opens files in remote sessions. Most of them aren't actually functions.

I'm all for getting the functions you listed implemented though. But I'd be hesitant to load them into every runspace we enter.

@TylerLeonhardt
Copy link
Member

Right, we're talking about expanding on the function that opens files. I'd rather not implement other functions (like New-EditorFile in a string in C#) It would be more valuable to have this pulled out to a PowerShell module so that the creating/cleaning is just a matter of importing and removing the module.

That also enables us to add other functions like the ones I mentioned above. We'd just add them to the module rather than messing with strings in C#.

@TylerLeonhardt
Copy link
Member

what's the issue loading them into every runspace? It's not that much logic, is it?

I think your hesitation is valid though which got me thinking...

what if *-EditorFile was a totally separate module and the user had the option to install it or not.

They could install it via Install-Module and use it. That way those that want it can have it, but it doesn't bloat up the runspaces.

^ (half thought - not fully thought out)

@SeeminglyScience
Copy link
Collaborator

@tylerl0706 Oh yeah they should definitely be in a module. Anything the user would actually call I think.
Aside from the proxy psedit command. Any reason we wouldn't put them in commands?

what's the issue loading them into every runspace? It's not that much logic, is it?

I guess it depends on what they do. For most things we'd need to set up events to forward back to the main session. If it was just loading functions then yeah it'd probably be fine.

@TylerLeonhardt
Copy link
Member

Now I feel like I'm missing something 😄

Aside from the proxy psedit command

Are you saying psedit can't go in "commands"? If so why can't it? If it can, I think it totally should go in commands.

@SeeminglyScience
Copy link
Collaborator

@tylerl0706 it most certainly can, in fact it already is :P

I was talking about the proxy psedit for remote sessions

@TylerLeonhardt
Copy link
Member

I see. So I guess the question is, what would we want to be loaded in a remote session?

I would think maybe open-editorfile and new-editorfile... That's it.

Side thought, do you think we could get away with folding new file creation into open-editorfile

Maybe that's not PowerShell-y 🤔

@SeeminglyScience
Copy link
Collaborator

Actually if open created files with a Force parameter that'd be pretty PowerShell-y. Plenty of precedent for that I think

@TylerLeonhardt
Copy link
Member

TylerLeonhardt commented Feb 5, 2018

and piping content into Open-EditorFile would still be PowerShell-y if given a -Force?

@TylerLeonhardt
Copy link
Member

irm mysite.com/foo.ps1 | open-editorfile foo.ps1 -force

@SeeminglyScience
Copy link
Collaborator

Yeah, New-Item's Value parameter takes pipeline input. I don't see why not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Extension Terminal Issue-Enhancement A feature request (enhancement).
Projects
None yet
Development

No branches or pull requests

4 participants