Current file in Run configuration
Answered
Hi guys.
Is it possible to pass to Bash Run configuration path to current IDEA file (file the cursor is inside or file selected in Project toolbar) or catalog (selected in Project toolbar)?
Maybe there is some magical variable $FILEPATH$ that you parse and substitute in Script parameters in Run configuration... (just like in Live templates).
I need this to run source code linter to lint current file I'm working in, not leaving IDEA and not going to external command line.
Please sign in to leave a comment.
Hi Alexander,
I do not know if those "magical variables" will work in Run Configuration .. but you can check the list of such supported "variables" in Settings | External Tools (just select any existing or create new one and then check out "Insert macro..." button)
Looks like variables from Settings | External Tools | Insert macro... doesn't work in Run configuration. I've checked $FilePath$ and $FileDir$ - they are left just as is.
Funny thing. I would use External Tool for my linting task, but "Edit tool" dialog seems doesn't support editing of enviroment variables (IDEA doesn't inherit parent envs so I need to customize PATH).
There is no variables substitution in Run configuration and there is no env customizing in External tools :-)
I think I'll add feature requests for these to YouTrack. Before filing a ticket I just wanted to be sure there is no way.
Andriy, thanks for your help.
Well ... you can create custom bash script where you customize your PATH and other environment variables and call all other commands from within.
Hmm, wrapper script with envs just for IDEA. To much noise I suppose :-)
Plus, I have several linting/build scripts and it's really convenient to pick one up out of Run popup list.
External tool requires a distinct shortcut for each tool (I think I wouldn't use mouse for that :) ) and for now even a wrapper environment script.
Anyway, good idea - I can live with that until (and if) implementing my feature request. Nobody knows when it's gonna happen...
Hi, any chance of this getting implemented?
Feel free to create feature request on YouTrack: http://youtrack.jetbrains.com/issues/IDEA.
https://youtrack.jetbrains.com/issue/IDEABKL-689 ?
I have made a workaround solution. The idea is to use a fixed location file for Script path in run configuration. But that file is a symlink to the current opened file. And in Before launch add an external tool - script that will update that symlink to current file. See my implementation here: https://gitlab.com/AndrewShark/pycharm-scripts/-/blob/main/relink_runme_file.sh
By the way, the same approach can be used for Redirect input file.
Edit: I used another idea. I change the workspace.xml, that way it changes the required fields. The benefit is that pycharm mentions the real file in tracebacks, instead of fake one symlinked runme.py. The disadvantage it that you need to run twice to switch. More info in the repo I linked above.
Edit 2: I made a fix for twice run disadvantage. The file is in repo I linked above.
Thanks a lot Ashark, very nice solution ….love it!!! <3
works btw. with a view adaptions also for webstorm and js files ;)