Satisfy Your Inner OCD: Introducing `inifmt` for Pretty INI Files

View this thread on: d.buzz | hive.blog | peakd.com | ecency.com
·@thecrazygm·
9.410 HBD
Satisfy Your Inner OCD: Introducing `inifmt` for Pretty INI Files
Hey everyone,

Today's post is about a little command-line tool I built for a very specific, and perhaps slightly obsessive, reason. I'm a bit OCD when it comes to formatting, and I've always found `.ini` style configuration files with misaligned equals signs to be visually jarring. They work fine, but they just don't _look_ nice. I looked at the inifmt that was available in the VSCode marketplace and underneath was an awk script, but didn't have many options.

So, because this is what we developers do, I built a tool for my own convenience to fix it. I call it `inifmt`.

#### What Does It Do?

`inifmt` is a simple utility written in Go that reads an `.ini` file and reformats it to perfectly align the equals signs, along with other normalizations like trimming excess whitespace.

For example, it can take a messy file like this `test.ini`:

```ini
; Test INI file for inifmt
; This file contains various INI formatting cases

[section1]
key1=value1
key2 =  value2
key3   =value3

[section2]
# Another comment style
longer_key_name=should_align
short=value

[section3] ; Inline comment
# Mixed comment styles
spaces   =   should   be   normalized
no_spaces=should_work_too
```

And with a simple command, turn it into this beautifully aligned `test2.ini`:

```ini
; Test INI file for inifmt
; This file contains various INI formatting cases

[section1]
key1            = value1
key2            = value2
key3            = value3

[section2]
# Another comment style
longer_key_name = should_align
short           = value

[section3] ; Inline comment
# Mixed comment styles
spaces          = should be normalized
no_spaces       = should_work_too
```


![It just looks so much better!](https://files.peakd.com/file/peakd-hive/thecrazygm/23swe5QvJjFPcT8mwtTDW9raAfDmMNrovUsE3twQo7NZYj3gxe2JycaFPD5c8ZW74vN4R.png)


Ah, much better! It's a small thing, but it makes config files so much easier to scan visually.

#### How It Works & Key Features

The tool is designed to be simple and flexible. It can read from a file directly or from standard input, so you can pipe content to it. It also has a few flags to control its behavior:

- **Global vs. Per-Section Alignment:** By default, it aligns everything based on the longest key in the entire file. If you prefer to align keys only within their own `[section]`, you can use the `--per-section` (or `-s`) flag.
- **In-Place Writing:** If you want to modify the file directly, you can use the `--write` (or `-w`) flag.
- **Simple Formatting:** If you don't want the alignment and just want to normalize the file to have single spaces around the equals sign, you can use the `--single-space` (or `-u`) flag.

#### Where to Find It

While I built this to scratch my own itch, I figured others might find it useful too. The code is open source and available on GitHub. The `README` has instructions for installation and usage.

- **GitHub Repository:** [https://github.com/TheCrazyGM/inifmt](https://github.com/TheCrazyGM/inifmt)

It’s a simple tool, but it's a great example of building something just because you want your digital workspace to be a little bit tidier. Let me know what you think!

As always,
Michael Garcia a.k.a. TheCrazyGM
👍 , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,