Skip to content

Commit

Permalink
Merge pull request #17 from yggdr/fix_exports
Browse files Browse the repository at this point in the history
Do not leave imports like "Path" around for the interactive session
  • Loading branch information
anki-code committed Apr 4, 2024
2 parents cdc16e2 + dfbb579 commit d8ccdc0
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions xontrib/prompt_starship.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
"""Starship cross-shell prompt in xonsh shell. """

import sys
import os
from pathlib import Path
import sys as _sys
from pathlib import Path as _Path


__xonsh__.env['STARSHIP_SHELL'] = 'xonsh'
__xonsh__.env['STARSHIP_SESSION_KEY'] = __xonsh__.subproc_captured_stdout(['starship','session']).strip()


def _starship_prompt(cfg: str) -> None:
import os
with __xonsh__.env.swap({'STARSHIP_CONFIG': cfg} if cfg else {}):
return __xonsh__.subproc_captured_stdout([
'starship', 'prompt',
Expand All @@ -25,9 +25,9 @@ def _starship_prompt(cfg: str) -> None:

_left_cfg = __xonsh__.env.get('XONTRIB_PROMPT_STARSHIP_LEFT_CONFIG' , __xonsh__.env.get('STARSHIP_CONFIG' , ''))
if _left_cfg:
_left_cfg = Path(_left_cfg).expanduser()
_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)
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:
Expand All @@ -36,21 +36,21 @@ def _starship_prompt(cfg: str) -> None:

_right_cfg = __xonsh__.env.get('XONTRIB_PROMPT_STARSHIP_RIGHT_CONFIG', '')
if _right_cfg:
_right_cfg = Path(_right_cfg).expanduser()
_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)
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', '')
if _bottom_cfg:
_bottom_cfg = Path(_bottom_cfg).expanduser()
_bottom_cfg = _Path(_bottom_cfg).expanduser()
if _bottom_cfg.exists():
__xonsh__.env['PROMPT_FIELDS']['starship_bottom_toolbar'] = lambda: _starship_prompt(_bottom_cfg)
if _replace:
__xonsh__.env['BOTTOM_TOOLBAR'] = '{starship_bottom_toolbar}'
else:
print(f"xontrib-prompt-starship: The path doesn't exist: {_bottom_cfg}", file=sys.stderr)
print(f"xontrib-prompt-starship: The path doesn't exist: {_bottom_cfg}", file=_sys.stderr)

0 comments on commit d8ccdc0

Please sign in to comment.