dploeger / idea.shellfilter

The IDEA Shell Filter plugin
https://plugins.jetbrains.com/plugin/9958-shell-filter
Other
5 stars 0 forks source link

shell command execution without text selection hangs Idea #2

Closed vemod closed 5 years ago

vemod commented 6 years ago

How to reproduce

expected behaviour on shell filter execution on editor without text selection:

p.s. similar plugin exists for Kate (kde editor) https://docs.kde.org/trunk5/en/applications/kate/kate-application-plugin-textfilter.html which is very nice plugin. frankly: expected same behaviour

dploeger commented 6 years ago

The plugin works in both ways. When you select a text, it will stream it to the shell's stdin. If you don't select text, it just executes the shell and returns the stdout.

With this in mind, would your shell command work, when there's no text coming into stdin?

If so, then this is clearly a bug. If not, I would propose on adding a "requires a text selection" check mark to the configuration dialog, so that the plugin would only show this command, if text was actually selected.

What do you say?

onetom commented 5 years ago

If I simply use the Custom option and provide cat as the "Shell command to run", that hangs without a selection too. I expected this to work and act as a no-op. I was also expecting the whole current file being piped in implicitly when nothing is selected.

The similar Sublime plugin - FilterPipes - has an option for this use-case:

All commands take the optional parameter use_selections, which when set to false, tells the system to ignore your text selections and pass the whole file in. Typically this is useful for tools that use the entire file for context, such as source code formatters.

I would argue that it's not even necessary to have this option, because one could just simply ignore the stdin (think echo -n asd | (echo qwe) prints qwe vsecho -n asd | (cat; echo qwe) prints asdqwe).

It might be useful though to pass the full source file path - if any - and the project and module root to the script, so it can include that information into the filter output or make decisions based on the path or extension...

My use-case would have been to automatically update the imported Ramda functions in my JavaScript source with ramda-destruct.

oscu0 commented 5 years ago

sort hangs if I don't have selection. I propose an option to timeout waiting for response or something.

dploeger commented 5 years ago

As no selection currently isn't really handled, I accept the request to pipe the whole file into it. This most probably wouldn't break current installations, too, because stdin will be removed for commands, that add just template text to the editor (which is the only usage I could think of right now)

However, I'll still make this a major version change, just to be sure.