From 83e0b4b9bdf7db6f863ff46b9441a56618e4390d Mon Sep 17 00:00:00 2001 From: "Hubert Van de Walle (huvw)" Date: Sun, 15 Jan 2023 13:03:08 +0100 Subject: [PATCH] Initial commit --- main.nim | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 main.nim diff --git a/main.nim b/main.nim new file mode 100644 index 0000000..a0cb879 --- /dev/null +++ b/main.nim @@ -0,0 +1,43 @@ +import parsecfg, os, tables, strutils + +type Profile = tuple[path: string, name: string] + +let file = "~/.mozilla/firefox/profiles.ini".expandTilde() +var dict = loadConfig(file) + +var profiles: seq[Profile] + +let installs = { + "release": "4F96D1932A9F858E", + "dev": "46F492E0ACFF84D4" +}.toTable + +let defaultInstall = "dev" + +for section in dict.sections(): + if section.startsWith("Profile"): + let name = dict.getSectionValue(section, "Name") + let path = dict.getSectionValue(section, "Path") + profiles.add((path, name)) + +proc current(): Profile = + let key = dict.getSectionValue("Install" & installs[defaultInstall], "Default") + for profile in profiles: + if profile.path == key: + return profile + +proc next(): Profile = + let current = current() + let index = profiles.find(current) + result = profiles[(index + 1) mod profiles.len] + +proc setNext() = + let next = next() + dict.setSectionKey("Install" & installs[defaultInstall], "Default", next.path) + dict.writeConfig(file) + +if paramCount() > 0 and paramStr(1) == "-c": + echo "{\"class\":\"" & current().name & "\"}" +else: + setNext() +