summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--modules/ini.inc11
1 files changed, 11 insertions, 0 deletions
diff --git a/modules/ini.inc b/modules/ini.inc
new file mode 100644
index 0000000..c4a098c
--- /dev/null
+++ b/modules/ini.inc
@@ -0,0 +1,11 @@
+# Get specific value from ini file
+# ini_get <file> <section> <key>
+ini_get () {
+ awk -v section="^\\\\s*\\\\[$2\\\\]" -v key="^\\\\s*$3\\\\s*=\\\\s*" '{if ($0 ~ section) {ins=1} else if ($0 ~ "^\\s*\\[") {ins=0} else if (ins && $0 ~ key) {gsub(key, ""); print; exit 0} }' "$1"
+}
+
+# List all sections in ini file
+# ini_sections <file>
+ini_sections () {
+ awk '{if (match($0, "^\\s*\\[([^\\]]*)\\]", a)) {print a[1]}}' "$1"
+}