9

In IntelliJ IDEA, how can I create a key binding that executes a shell script with the current file as a parameter?

For exanmple, if I am in a test file (entity.spec.js), I want to save and hit a key binding to trigger a shell script with that file as the parameter:

./run_test.sh /full/path/to/entity.spec.js

Any idea how to do that?

1 Answers1

11

You can do it using the External Tools. Then you can assign a keyboard shortcut to your tool in Settings | Keymap.

Please note that you should specify your shell interpreter as a Program for the external tool (such as /bin/bash) and pass your script path and the file name as Parameters. Use Insert Macro button to add a macro for the current editor file path.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
  • I'm trying to bind to S which is the same as save all. If i remove the hotkey from save all it works, however if I don't remove the binding it does not. This should be OK because IntelliJ saves as I type, correct? – Carlos Bribiescas Jan 14 '16 at 18:31
  • @CarlosBribiescas it doesn't save as you type, it saves before run, before compilation, on exit, before commit, etc. There is also a setting to save files periodically. – CrazyCoder Jan 15 '16 at 10:06
  • Ok, in that case I need the double binding to work in order. Do you know how i would do that? – Carlos Bribiescas Jan 15 '16 at 14:42
  • @CarlosBribiescas sure, just record a macro with these 2 actions and assign a shortcut to the macro instead. – CrazyCoder Jan 15 '16 at 14:43