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()