commit 6af26dbdd29c7bd7ad4305265635f450f8688e03
parent b667e5bb0dde12121990eab026ad2de340964648
Author: Isak Lindhé <isak.e.lindhe@gmail.com>
Date: Thu, 17 Jan 2019 19:37:17 +0100
oh, config wasnt tracked
Diffstat:
1 file changed, 35 insertions(+), 0 deletions(-)
diff --git a/src/config.py b/src/config.py
@@ -0,0 +1,35 @@
+from pathlib import Path
+import configparser
+
+CONFIG_DIR = Path.home() / '.config' / 'svtxtv'
+
+def get_or_gen_config(config_path: Path = CONFIG_DIR / 'svtxtv.conf'):
+ cfg = configparser.ConfigParser()
+ if config_path.exists():
+ cfg.read_file(open(config_path, 'r'))
+ else:
+ cfg['color'] = {
+ 'header' : 'yellow',
+ 'frame' : 'blue',
+ }
+ cfg['alias'] = {
+ '__DEFAULT__' : '100', # magic alias, will be used when given no arguments.
+ 'inrikes':'101',
+ 'in':'101',
+ 'utrikes':'104',
+ 'ut':'104',
+ 'innehÄll':'700',
+ }
+ if not CONFIG_DIR.exists():
+ CONFIG_DIR.mkdir()
+ cfg.write(open(config_path, 'w'))
+ return cfg
+
+
+def apply_aliases(txt: str, cfg: configparser.ConfigParser) -> str:
+ txt = txt.strip()
+ if 'alias' in cfg and txt in cfg['alias']:
+ return cfg['alias'][txt]
+ else:
+ return txt
+