iniq
a command-line tool to query INI files
iniq is like jq for INI data. You can use it to format, and filter INI data with ease. (jq can do more than iniq but that's by design.)
iniq is written in Crystal and has no runtime dependencies.
iniq tries to do only one thing and to do it well, in line with the unix philosphy.
With iniq you can fetch values or whole sections from INI files.
You may not realise it but INI files are everywhere. For example, they are used by Thunderbird and Firefox including many extensions for those apps. I have 572 ini files on this computer (sudo find / -name \*.ini | wc -l
) which is a lot more than I expected.
Besides the obvious files with .ini
extension, every PLS playlist is an INI
file too and git is using the format extensively for a multitude of config files.
Ansible, .desktop files, ... SystemD scripts
Invoking iniq
Since the output if iniq is almost always in INI format you can parse this output again with iniq. This means that can chain multiple calls to iniq with the pipe operators like this: cat file.ini | iniq "[main]" | iniq "foobar"
Examples
Format an INI file
$ cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = git@github.com:rails/rails.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
$ iniq .git/config
[core]
repositoryformatversion=0
filemode=true
bare=false
logallrefupdates=true
[remote "origin"]
url=git@github.com:rails/rails.git
fetch=+refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote=origin
merge=refs/heads/master
Another way to do this would be like such:
$ cat .git/config | iniq
Fetching a section
$ iniq .git/config "[core]"
repositoryformatversion=0
filemode=true
bare=false
logallrefupdates=true
$ iniq .git/config "[branch \"master\"]"
remote=origin
merge=refs/heads/master
Fetching one value
$ iniq .git/config "[branch \"master\"]" remote
origin
Values outside of sections
You could have an INI file with no sections, or you need to access values that exist before/outside any section like in this file:
$ iniq /opt/android-sdk/[...]-19/manifest.ini
name=Glass Development Kit Preview
name-id=google_gdk
vendor=Google Inc.
vendor-id=google
description=Preview of the Glass Development Kit
api=19
revision=5
libraries=com.google.android.glass;
com.google.android.glass=gdk.jar;APIs for Glass Development Kit Preview
If you want to fetch a value that's not inside any section you can use the pseudo section "[]"
$ iniq /opt/android-sdk/[...]-19/manifest.ini "[]" description
Preview of the Glass Development Kit
or omit the section argument altogether:
$ iniq /opt/android-sdk/[...]-19/manifest.ini description
Preview of the Glass Development Kit
You can also use the psuedo section to fetch all top-level values.
$ iniq /opt/android-sdk/[...]-19/manifest.ini "[]"
name=Glass Development Kit Preview
name-id=google_gdk
vendor=Google Inc.
vendor-id=google
description=Preview of the Glass Development Kit
api=19
revision=5
libraries=com.google.android.glass;
com.google.android.glass=gdk.jar;APIs for Glass Development Kit Preview