A NodeJS CLI to reformat your Clojure(Script) code using cljfmt.
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'
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.
Windows will not recognize this as an executable file, use node <path-to-cljfmt>
to execute.
Note: You must have installed the CLI first.
- Navigate to File > Settings.
- Navigate to Tools > External Tools.
- Click green plus (+) button to create a new External Tool.
- Input a name for your external tool. We'll use cljfmt.
- Deselect "Open console" (deselecting this will allow the formatter to run in the background with no UI interruptions)
- Set program to the location that you installed
cljfmt
to. Ifcljfmt
is on your path then you can simply usecljfmt
. - 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."
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
}