diff options
| author | Pavel Egorov <[email protected]> | 2025-12-16 13:40:05 +0300 |
|---|---|---|
| committer | Pavel Egorov <[email protected]> | 2025-12-16 13:40:05 +0300 |
| commit | 9c201421517b485f9c81bbd167a73f77352be4e6 (patch) | |
| tree | 460f86cfc2d7346101d2658459c92c26eb2bfed0 | |
| parent | 6029273a4af8eaab0d36536b45a7d46f1887ad5e (diff) | |
| download | dotfiles-9c201421517b485f9c81bbd167a73f77352be4e6.tar.gz dotfiles-9c201421517b485f9c81bbd167a73f77352be4e6.zip | |
[fastfetch] dump config and run fastfetch on it
| -rw-r--r-- | .config/fastfetch/confgen.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/.config/fastfetch/confgen.py b/.config/fastfetch/confgen.py index de1bda5..d4983b5 100644 --- a/.config/fastfetch/confgen.py +++ b/.config/fastfetch/confgen.py | |||
| @@ -1,6 +1,9 @@ | |||
| 1 | #!/usr/bin/env python3 | 1 | #!/usr/bin/env python3 |
| 2 | 2 | ||
| 3 | from typing import Optional, Any, Iterator | 3 | from typing import Optional, Any, Iterator |
| 4 | import json | ||
| 5 | from tempfile import NamedTemporaryFile | ||
| 6 | import subprocess | ||
| 4 | 7 | ||
| 5 | 8 | ||
| 6 | def flatten(obj) -> Iterator[Any]: | 9 | def flatten(obj) -> Iterator[Any]: |
| @@ -182,6 +185,7 @@ roots = [ | |||
| 182 | modules["gpu"].add_children(modules["gpu_driver"]), | 185 | modules["gpu"].add_children(modules["gpu_driver"]), |
| 183 | modules["disk"], | 186 | modules["disk"], |
| 184 | modules["ram"].add_children(modules["swap"]), | 187 | modules["ram"].add_children(modules["swap"]), |
| 188 | modules["battery"], | ||
| 185 | ), | 189 | ), |
| 186 | modules["display"] | 190 | modules["display"] |
| 187 | ), | 191 | ), |
| @@ -193,5 +197,18 @@ roots = [ | |||
| 193 | ), | 197 | ), |
| 194 | ] | 198 | ] |
| 195 | 199 | ||
| 200 | modules = {"modules": list(flatten(root.collect_branch() for root in roots))} | ||
| 201 | |||
| 202 | with NamedTemporaryFile(mode='w', delete_on_close=False, suffix=".jsonc") as tmp_config: | ||
| 203 | json.dump(schema | logo | modules, tmp_config) | ||
| 204 | tmp_config.flush() | ||
| 205 | |||
| 206 | fastfetch_response = subprocess.run( | ||
| 207 | ["fastfetch", "--config", tmp_config.name, "--json"], | ||
| 208 | capture_output=True | ||
| 209 | ) | ||
| 210 | |||
| 211 | fastfetch_data = json.loads(fastfetch_response.stdout) | ||
| 212 | |||
| 213 | print(json.dumps(fastfetch_data, indent=2)) | ||
| 196 | 214 | ||
| 197 | modules = [flatten(root.collect_branch()) for root in roots] | ||
