From ab8fe0cb496def48c6b6b63711c2d6c11a2f61ac Mon Sep 17 00:00:00 2001 From: zackartz Date: Sun, 16 Jun 2024 00:07:09 -0400 Subject: [PATCH] 751 current 2024-06-16 00:07:08 24.11.20240615.24b048f 6.9.3-zen1 * --- catpuccin.omp.json | 70 +++++++++++++++++++++++++++++++++++ json2nix.py | 92 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 162 insertions(+) create mode 100644 catpuccin.omp.json create mode 100644 json2nix.py diff --git a/catpuccin.omp.json b/catpuccin.omp.json new file mode 100644 index 0000000..2accb92 --- /dev/null +++ b/catpuccin.omp.json @@ -0,0 +1,70 @@ +{ + "palette": { + "os": "#ACB0BE", + "pink": "#F5BDE6", + "lavender": "#B7BDF8", + "blue": "#8AADF4", + "wight": "#FFFFFF", + "text": "#494D64" + }, + "blocks": [ + { + "alignment": "left", + "segments": [ + { + "background": "p:blue", + "foreground": "p:wight", + "powerline_symbol": "\ue0b4", + "leading_diamond": "\ue0b6", + "style": "diamond", + "template": "{{.Icon}} ", + "type": "os" + }, + { + "background": "p:blue", + "foreground": "p:text", + "powerline_symbol": "\ue0b4", + "style": "diamond", + "template": "{{ .UserName }}@{{ .HostName }}", + "type": "session" + }, + { + "background": "p:pink", + "foreground": "p:text", + "properties": { + "folder_icon": "..\ue5fe..", + "home_icon": "~", + "style": "agnoster_short" + }, + "powerline_symbol": "\ue0b4", + "style": "powerline", + "template": " {{ .Path }}", + "type": "path" + }, + { + "background": "p:lavender", + "foreground": "p:text", + "style": "powerline", + "properties": { + "branch_icon": "\ue725 ", + "cherry_pick_icon": "\ue29b ", + "commit_icon": "\uf417 ", + "fetch_status": false, + "fetch_upstream_icon": false, + "merge_icon": "\ue727 ", + "no_commits_icon": "\uf0c3 ", + "rebase_icon": "\ue728 ", + "revert_icon": "\uf0e2 ", + "tag_icon": "\uf412 " + }, + "powerline_symbol": "\ue0b4", + "template": " {{ .HEAD }}", + "type": "git" + } + ], + "type": "prompt" + } + ], + "final_space": true, + "version": 2 +} diff --git a/json2nix.py b/json2nix.py new file mode 100644 index 0000000..40d8576 --- /dev/null +++ b/json2nix.py @@ -0,0 +1,92 @@ +# Original script: https://gist.githubusercontent.com/Scoder12/0538252ed4b82d65e59115075369d34d/raw/e86d1d64d1373a497118beb1259dab149cea951d/json2nix.py +"""Converts JSON objects into nix (hackishly).""" + +import sys +import json + + +INDENT = " " * 2 + + +def strip_comments(t): + # fixme: doesn't work if JSON strings contain // + return "\n".join(l.partition("//")[0] for l in t.split("\n")) + + +def indent(s): + return "\n".join(INDENT + i for i in s.split("\n")) + + +def nix_stringify(s): + # fixme: this doesn't handle string interpolation and possibly has more bugs + return json.dumps(s) + + +def sanitize_key(s): + if s and s.isalnum() and not s[0].isdigit(): + return s + return nix_stringify(s) + + +def flatten_obj_item(k, v): + keys = [k] + val = v + while isinstance(val, dict) and len(val) == 1: + k = next(iter(val.keys())) + keys.append(k) + val = val[k] + return keys, val + + +def fmt_object(obj, flatten): + fields = [] + for k, v in obj.items(): + if flatten: + keys, val = flatten_obj_item(k, v) + formatted_key = ".".join(sanitize_key(i) for i in keys) + else: + formatted_key = sanitize_key(k) + val = v + fields.append(f"{formatted_key} = {fmt_any(val, flatten)};") + + return "{\n" + indent("\n".join(fields)) + "\n}" + + +def fmt_array(o, flatten): + body = indent("\n".join(fmt_any(i, flatten) for i in o)) + return f"[\n{body}\n]" + + +def fmt_any(o, flatten): + if isinstance(o, str) or isinstance(o, bool) or isinstance(o, int): + return json.dumps(o) + if isinstance(o, list): + return fmt_array(o, flatten) + if isinstance(o, dict): + return fmt_object(o, flatten) + raise TypeError(f"Unknown type {type(o)!r}") + + +def main(): + flatten = "--flatten" in sys.argv + args = [a for a in sys.argv[1:] if not a.startswith("--")] + + if len(args) < 1: + print(f"Usage: {sys.argv[0]} [--flatten] ", file=sys.stderr) + sys.exit(1) + + with open(args[0], "r") as f: + contents = f.read().strip() + if contents[-1] == ",": + contents = contents[:-1] + if contents[0] != "{": + contents = "{" + contents + "}" + data = json.loads(strip_comments(contents)) + + outputs = fmt_any(data, flatten=flatten) + print(outputs[1:-1]) + + +if __name__ == "__main__": + main() +