Skip to content

Commit

Permalink
Merge pull request #15 from yggdr/fix_paths_v2
Browse files Browse the repository at this point in the history
Fix treatment of config paths - version 2
  • Loading branch information
anki-code committed Mar 19, 2024
2 parents 267fba7 + 2f4f591 commit a1f8ef2
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 a1f8ef2

Please sign in to comment.