parse a config file to get terimnal
This commit is contained in:
parent
9631f273e9
commit
db9b26dcbf
2 changed files with 36 additions and 1 deletions
33
scripts/parse_config.py
Normal file
33
scripts/parse_config.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
import configparser
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import Dict
|
||||
|
||||
# We read a configuration file for university setup that is located
|
||||
# in $XDG_CONFIG_HOME/university-setup/config.cfg
|
||||
# We follow standard configparser procedure
|
||||
|
||||
|
||||
def get_config_file():
|
||||
if 'XDG_CONFIG_HOME' in os.environ.keys():
|
||||
xdg_config_home = Path(os.environ['XDG_CONFIG_HOME']).resolve()
|
||||
else:
|
||||
xdg_config_home = Path('~/.config').resolve()
|
||||
return xdg_config_home / 'university-setup' / 'config.cfg'
|
||||
|
||||
|
||||
def get_config(section_name: str = 'Subprocess') -> Dict:
|
||||
parser = configparser.RawConfigParser()
|
||||
parser.read(get_config_file())
|
||||
if section_name in parser:
|
||||
return dict(parser[section_name])
|
||||
else:
|
||||
return {}
|
||||
|
||||
|
||||
def terminal() -> str:
|
||||
d = get_config('Subprocess')
|
||||
if 'terminal' in d.keys():
|
||||
return d['terminal']
|
||||
else:
|
||||
return 'i3-sensible-terminal'
|
|
@ -4,12 +4,14 @@ import subprocess
|
|||
from pathlib import Path
|
||||
import os
|
||||
|
||||
from parse_config import terminal
|
||||
|
||||
|
||||
def edit(filepath: Path, rootpath: Path = None, env=os.environ, servername='tex lecture'):
|
||||
if not rootpath:
|
||||
rootpath = filepath.root
|
||||
subprocess.Popen([
|
||||
"i3-sensible-terminal",
|
||||
terminal(),
|
||||
"-e",
|
||||
f"vim --servername {servername} --remote-silent {str(filepath)}"
|
||||
], env=env, cwd=str(rootpath))
|
||||
|
|
Loading…
Reference in a new issue