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

Pass file type to "Send Selection" commands #2156

Open
GFdevelop opened this issue May 18, 2019 · 4 comments
Open

Pass file type to "Send Selection" commands #2156

GFdevelop opened this issue May 18, 2019 · 4 comments

Comments

@GFdevelop
Copy link

How can I use "Send selection to" based on file type? At this time I'm have multiple shortcuts, for example:
prettify json CTRL+1 --> prettier --parser json
prettify css CTRL+2 --> prettier --parser css
compact json CTRL+3 --> minify --type json
compact css CTRL+4 --> minify --type css
etc...
My idea is to have:
prettify CTRL+1 --> prettier --parser %e
compact CTRL+2 --> minify --type %e
where %e is the type of file.
Is there any existing solution?

@codebrainz
Copy link
Member

I thought I remembered an Issue or Pull Request to pass certain information like this to commands using environment variables, but I can't find it.

@codebrainz codebrainz changed the title [FEATURE-REQUEST] prettify and compact Pass file type to "Send Selection" commands May 18, 2019
@elextr
Copy link
Member

elextr commented May 19, 2019

@codebrainz might be thinking of templates commands where environment variables and set, but custom commands do not seem to do so.

I tend to prefer the command arguments approach over the environment variables since no existing command will understand the GEANY_XXX variables so their use is restricted to shell scripts or user written commands, but there is a chance that and existing command might understand something like the filetype passed as an argument the way @GFdevelop showed. But a % letter should be chosen to not overlap with the build command replacements, so %e is taken. Perhaps %t for fileType.

@GFdevelop
Copy link
Author

A better solution would be to add an option in build menu to reload the document after a command execution (prettier %f && geany %f) or to replace all text with the command output, because I can use different command and different options based on filetype, for example minify https://github.com/tdewolff/minify have support only for 6 filetype but I want to minimize other formats with different command.
Example:
json prettify: python -m json.tool %f
json compact: jq -c . %f
css prettify: prettier %f
css compact: minify %f

@elextr
Copy link
Member

elextr commented May 19, 2019

Build commands are intended to operate off saved files and the output is parsed for error messages, not to replace the contents.

Prettification is something that the custom commands are intended to handle as they get the contents of the buffer or selection (not a saved file) and replace them in the buffer with the command output, exactly what you want because it doesn't overwrite your file until you are satisfied with it and hit save.

All it needs is, as was originally requested, the ability to pass some filetype information to the command so the correct prettifying is applied. If the command doesn't do that or if you want to choose between different commands, a script can do it based on the filetype passed to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants