From 2f4f5913696cac37740e8dd681ded29beb5f21b3 Mon Sep 17 00:00:00 2001 From: Konstantin Schukraft Date: Mon, 18 Mar 2024 02:03:46 +0100 Subject: [PATCH] Fix treatment of config paths --- xontrib/prompt_starship.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/xontrib/prompt_starship.py b/xontrib/prompt_starship.py index 742756b..fa79d72 100644 --- a/xontrib/prompt_starship.py +++ b/xontrib/prompt_starship.py @@ -9,7 +9,7 @@ __xonsh__.env['STARSHIP_SESSION_KEY'] = __xonsh__.subproc_captured_stdout(['starship','session']).strip() -def _starship_prompt(cfg=None): +def _starship_prompt(cfg: str) -> None: with __xonsh__.env.swap({'STARSHIP_CONFIG': cfg} if cfg else {}): return __xonsh__.subproc_captured_stdout([ 'starship', 'prompt', @@ -19,14 +19,15 @@ def _starship_prompt(cfg=None): '--terminal-width', str(os.get_terminal_size().columns), ]) - + _replace = __xonsh__.env.get('XONTRIB_PROMPT_STARSHIP_REPLACE_PROMPT' , True) - - -_left_cfg = __xonsh__.env.get('XONTRIB_PROMPT_STARSHIP_LEFT_CONFIG' , '') -_left_cfg = Path(_left_cfg).expanduser() if _left_cfg else _left_cfg -if _left_cfg and not _left_cfg.exists(): - print(f"xontrib-prompt-starship: The path doesn't exist: {_left_cfg}", file=sys.stderr) + + +_left_cfg = __xonsh__.env.get('XONTRIB_PROMPT_STARSHIP_LEFT_CONFIG' , __xonsh__.env.get('STARSHIP_CONFIG' , '')) +if _left_cfg: + _left_cfg = Path(_left_cfg).expanduser() + if not _left_cfg.exists(): + print(f"xontrib-prompt-starship: The path doesn't exist: {_left_cfg}", file=sys.stderr) __xonsh__.env['PROMPT_FIELDS']['starship_left'] = lambda: _starship_prompt(_left_cfg) if _replace: @@ -34,8 +35,8 @@ def _starship_prompt(cfg=None): _right_cfg = __xonsh__.env.get('XONTRIB_PROMPT_STARSHIP_RIGHT_CONFIG', '') -_right_cfg = Path(_right_cfg).expanduser() if _right_cfg else _right_cfg if _right_cfg: + _right_cfg = Path(_right_cfg).expanduser() if _right_cfg.exists(): __xonsh__.env['PROMPT_FIELDS']['starship_right'] = lambda: _starship_prompt(_right_cfg) if _replace: @@ -43,10 +44,10 @@ def _starship_prompt(cfg=None): else: print(f"xontrib-prompt-starship: The path doesn't exist: {_right_cfg}", file=sys.stderr) - + _bottom_cfg = __xonsh__.env.get('XONTRIB_PROMPT_STARSHIP_BOTTOM_CONFIG', '') -_bottom_cfg = Path(_bottom_cfg).expanduser() if _bottom_cfg else _bottom_cfg if _bottom_cfg: + _bottom_cfg = Path(_bottom_cfg).expanduser() if _bottom_cfg.exists(): __xonsh__.env['PROMPT_FIELDS']['starship_bottom_toolbar'] = lambda: _starship_prompt(_bottom_cfg) if _replace: