Use Command Line Tools to run an external command on an open file in IDEA?

Answered

I'd like to run an external command on an open file in IDE. I know I can use the Command Line Tool Support plugin to run external commands from within IDEA, and by itself that works fine. However, when defining a Command Line Tool Command I could not find a way to parameterise the command. Specifically I would like to define a command such that it run on a file I have currently open and in-focus in an editor. So I would need access to some variabele or predefined method that would return the full path to that file. So kind of like the variables and methods available in 'Live Templates'.

Anyone an idea if this is possible at all? (I could not find any hints on this in the IDEA help I'm affraid).

To give an actual example of what I'd like to do:

  • I have a Groovy script open in an editor tab.
  • I have a Command Line Tool defined that will call the 'groovyclient'-executable. (Off-topic: checkout GroovyServ project on why I would want this.)
  • As a parameter the 'groovyclient'-executable would take the full path to the file in the editor-tab

Does IDEA provide some variable or method I could use in my Tool definition that would resolve into this path?

 

2 comments
Comment actions Permalink

You can do it with external tools, there are variables for current file path.

https://www.jetbrains.com/help/idea/2016.2/external-tools.html

0
Comment actions Permalink

Ah, great! Thanks Serge! This indeed does exactly what I want, with the added bonus of showing the configured tool in the context menu. Nice! Probably a shortcut can be added then as well.

Leaves me still a bit confused though: Wy do we have both Command Line Tool Support (with option 'globally visible') and External Tools? They seem different implementations of the same thing: ability to run some external program on files in IDEA... Are there different use cases for these tools that you know of?

0

Please sign in to leave a comment.