Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute command on saving a file in Intellij IDEA [closed]

I'd like to run a script when a file gets saved. (It's an automatic git commit in the vein of git-wip). It's related to Save actions in IntelliJ IDEA, but it mostly attracted answers about code reformatting. It was also asked 3 years ago. The only snippet I found was http://arhipov.blogspot.hu/2011/04/code-snippet-intercepting-on-save.html. So I wonder if things have changed and now it's easy to add a save-hook.

like image 365
Adam Schmideg Avatar asked Jan 01 '14 12:01

Adam Schmideg


People also ask

How do I save a file in IntelliJ?

Press Ctrl+S or select File | Save All from the main menu.

What is the Run command in IntelliJ?

Run applications Last modified: 28 July 2022. Run a class with a main() method: Shift+F10. You can run applications right from IntelliJ IDEA if you have an SDK set up for your project/module.

How do I turn off auto save in IntelliJ?

In File > Settings > Appearance & Behavior > System Settings, under Synchronization, do you have checked the option of "Save files automatically if application is idle for xxxx sec." ? Why not disable it totally? My version of IntelliJ IDEA has a check-mark on this option that when unchecked it disables it.

How do I stop terminal execution in IntelliJ?

You can run a process with ⌃R (macOS), or Shift+F10 (Windows/Linux). To stop a process, you can use ⌘F2 on macOS, or Ctrl+F2 on Windows/Linux.


1 Answers

I think you have at least two options:

  1. Use the File Watchers plugin from JetBrains:

    • Plugin: http://plugins.jetbrains.com/plugin?pr=idea&pluginId=7177
    • Doc: https://www.jetbrains.com/idea/help/using-file-watchers.html

    NB: Doesn't work on IntelliJ Idea 11.

  2. Use a similar program outside of IntelliJ. I'm using fswatch (works on Unix-based OSes, including OSX) installed via MacPorts (port install fswatch):

    https://github.com/emcrisostomo/fswatch

like image 72
jonathanpdx Avatar answered Sep 28 '22 23:09

jonathanpdx