Child pages
  • Command-Line Source Code Formatter
Skip to end of metadata
Go to start of metadata

Please check the official Command Line Formatter help page.

Running Command-Line Formatter when the IDE is Running

On Linux/MacOS

  • Go to <Intellij Home>/bin directory where <Intellij Home> is a directory where Intellij IDEA or Intellij IDEA-based product is installed.
  • Copy idea.properties to some other file, for example, format.properties
  • Modify format.properties as follows:

    1. Uncomment the lines:
      # idea.config.path=${user.home}/.IntelliJIdea/config

      and
      # idea.system.path=${user.home}/.IntelliJIdea/system

    2. Change them to point to some directories which differ from defaults, for example:
      idea.config.path=${user.home}/.IntelliJIdea/format/config
      idea.system.path=${user.home}/.IntelliJIdea/format/system
              
  • Modify format.sh by adding the line with IDEA_PROPERTIES variable:
    #!/bin/sh
    # ------------------------------------------------------
    # IntelliJ IDEA formatting script.
    # ------------------------------------------------------
    
    IDE_BIN_HOME="${0%/*}"
    export IDEA_PROPERTIES=$IDE_BIN_HOME/format.properties
    exec "$IDE_BIN_HOME/idea.sh" format "$@"
        
  • Run format.sh without closing the IDE, it should give the following output:
    IntelliJ IDEA ..., build ... Formatter
    Usage: format [-h] [-r|-R] [-s|-settings settingsPath] path1 path2...
      -h|-help       Show a help message and exit.
      -s|-settings   A path to Intellij IDEA code style settings .xml file.
      -r|-R          Scan directories recursively.
      -m|-mask       A comma-separated list of file masks.
      path..         A path to a file or a directory.
    

On Windows

  • You have to create a separate format.properties file as described above for Linux/MacOS.
  • Change format.bat file by adding a line with IDEA_PROPERTIES variable as follows:
    
    @ECHO OFF
    ::----------------------------------------------------------------------
    :: IntelliJ IDEA formatting script.
    ::----------------------------------------------------------------------
    SET IDE_BIN_DIR=%~dp0
    SET IDEA_PROPERTIES=%IDE_BIN_DIR%\format.properties
    CALL "%IDE_BIN_DIR%\idea.bat" format %*
  • Run format.bat, it will list the command-line formatter options.
  • No labels