/cljfmt-cli

A NodeJS CLI to reformat your Clojure(Script) code.

Primary LanguageClojure

cljfmt-cli

A NodeJS CLI to reformat your Clojure(Script) code using cljfmt.

Installation

Here is a one-liner to install cljfmt to /usr/local/bin:

bash -c 'sudo curl -fsSLo /usr/local/bin/cljfmt https://github.com/ComputeSoftware/cljfmt-cli/releases/download/v1.2/cljfmt && sudo chmod +x /usr/local/bin/cljfmt'

Installation from source

You will need Boot installed on your system. Clone this repo and run this command:

boot prod-build target

This will build the NodeJS script to the target directory. Inside the target directory you will find a file named cljfmt. Let's make this file executable.

chmod +x target/cljfmt

Now place cljfmt somewhere convenient on your system. Often users will place it somewhere on their PATH.

Note for Windows

Windows will not recognize this as an executable file, use node <path-to-cljfmt> to execute.

Usage in IntelliJ

Note: You must have installed the CLI first.

  1. Navigate to File > Settings.
  2. Navigate to Tools > External Tools.
  3. Click green plus (+) button to create a new External Tool.
  4. Input a name for your external tool. We'll use cljfmt.
  5. Deselect "Open console" (deselecting this will allow the formatter to run in the background with no UI interruptions)
  6. Set program to the location that you installed cljfmt to. If cljfmt is on your path then you can simply use cljfmt.
  7. Set parameters to --fix $FilePath$.

To run the external tool, navigate to Tools > External Tools > cljfmt. This will run the formatter on your currently selected file.

You can take this one step further and bind the formatter to some keys. To do this, navigate to File > Settings > Keymap. Then go to External Tools > External Tools and find the name of your external tool. Double click it and select "Add Keyboard Shortcut."

Usage in Atom

Install the atom-shell-commands plugin (). Open the config file (File->Config...), and add an entry in commands: array of the "atom-shell-commands" config. Following is an example for Windows:

{
  name: "cljfmt"
  command: "node"
  arguments: ["C:/Users/dave/bin/cljfmt", "--fix", "{FilePath}"]
  options:
    keymap: "ctrl-shift-i"
    save: true
}