122

Is there a way by which a shell script can be invoked from IntelliJ Run/Debug configurations?

mate64
  • 9,876
  • 17
  • 64
  • 96
Sundar Annamalai
  • 2,240
  • 2
  • 16
  • 20
  • 5
    **If you want to see such a feature in PyCharm please vote on [IDEA-112256 'Command Line' Run Configuration](https://youtrack.jetbrains.com/issue/IDEA-112256) feature request.** – Piotr Dobrogost Apr 14 '17 at 08:32

5 Answers5

79

I just found out that we can invoke a shell script with the help of BashSupport plugin.

Anton Dozortsev
  • 4,782
  • 5
  • 34
  • 69
Sundar Annamalai
  • 2,240
  • 2
  • 16
  • 20
  • 3
    Any ideia of how to debug it? – valdeci Aug 16 '18 at 14:27
  • 2
    BashSupport plugin is deprecated after IDEA 2020.2, and now the paid [BashSupport Pro](https://www.bashsupport.com/pro/) is used. However, the -[Shell Script](https://plugins.jetbrains.com/plugin/13122-shell-script) plugin can still be used – Tcheutchoua Steve Mar 03 '21 at 15:54
69

'Add External tool' in the 'Before Launch' does the trick.

Screenshot

edit tool add shell script

mate64
  • 9,876
  • 17
  • 64
  • 96
Siddhartha
  • 4,296
  • 6
  • 44
  • 65
  • 3
    This worked well - thank you. I used Program: ` C:\Program Files (x86)\Git\bin\rm.exe ` And Parameters: ` -fr ~/.grails/.slcache/ ` As another example – Ask613 Mar 06 '15 at 15:27
  • 3
    Doesn't this still run one of the standard run/debug configurations *after* running this external script? What if you wanted to only run your own external script? – Greg Bell Jan 26 '17 at 04:37
  • 2
    To find the path to `sh` or `bash`, enter `which sh` or `which bash` in a shell. You can use `$ProjectFileDir$` as the *Working directory*, which is a macro pointing to the project root directory. Other macros (e.g. for module specific directories) can be found under the *Insert macro...* button. – Erik Oct 07 '17 at 09:57
  • 2
    what if I need it after launch? – xeruf May 17 '18 at 11:36
21

IntelliJ IDEA 2019.2 update

New version of IntelliJ IDEA has Shell Script Support included. It means you can now create Shell Script build for your project.

Edit Configurations > (+) Add New Configuration > Shell Script

You can also build your project before executing your script by adding Run Another Configuration task. That's how it looks like: Add Shell Build window

Kyriet
  • 401
  • 5
  • 8
  • 1
    Alas, if a java debug configuration uses a shell script in "Run Another Configuration", then only the shell script is started. The debug session isn't. – Auric Sep 23 '19 at 12:21
  • 1
    @Auric there is an issue for this: https://youtrack.jetbrains.com/issue/IDEA-229741 – Andrey Feb 13 '20 at 16:03
  • Any idea how to keep the shell window open after execution? or even just to print the output to IntelliJs own console? – SH151 Oct 22 '20 at 08:28
10

Not sure about 11, but in 12 there's a part of Run/Debug Configuration that is called "Before Launch" and you can select your shell script in "Add External tool" option.

Vic
  • 21,473
  • 11
  • 76
  • 97
1

Create a custom shell script first. custom shell Then, add that to "Before Launch" in the next npm run. add before launch

Bira
  • 4,531
  • 2
  • 27
  • 42