Skip to content

Commit

Permalink
Fix treatment of config paths
Browse files Browse the repository at this point in the history
  • Loading branch information
yggdr committed Mar 19, 2024
1 parent 267fba7 commit 2f4f591
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions xontrib/prompt_starship.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -19,34 +19,35 @@ 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:
__xonsh__.env['PROMPT'] = '{starship_left}'


_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:
__xonsh__.env['RIGHT_PROMPT'] = '{starship_right}'
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:
Expand Down

0 comments on commit 2f4f591

Please sign in to comment.