summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Knaack <davidkna@users.noreply.github.com>2021-12-31 08:23:01 +0100
committerGitHub <noreply@github.com>2021-12-31 08:23:01 +0100
commit2b405042b90ad88484fb1d90a822ed2f9494619e (patch)
tree1ef8bf351bb3c276508052fab7fdbc92cfe39f74
parentc5a5fc28206df73e963967f27eacd58c1236e278 (diff)
feat(xonsh): support rprompt (#3362)
-rw-r--r--docs/advanced-config/README.md2
-rw-r--r--src/init/starship.xsh11
2 files changed, 12 insertions, 1 deletions
diff --git a/docs/advanced-config/README.md b/docs/advanced-config/README.md
index 2b768a68d..15698e330 100644
--- a/docs/advanced-config/README.md
+++ b/docs/advanced-config/README.md
@@ -121,7 +121,7 @@ not explicitly used in either `format` or `right_format`.
Note: The right prompt is a single line following the input location. To right align modules above
the input line in a multi-line prompt, see the [fill module](/config/#fill).
-`right_format` is currently supported for the following shells: elvish, fish, zsh.
+`right_format` is currently supported for the following shells: elvish, fish, zsh, xonsh.
### Example
diff --git a/src/init/starship.xsh b/src/init/starship.xsh
index 64439d203..a14ad9968 100644
--- a/src/init/starship.xsh
+++ b/src/init/starship.xsh
@@ -11,7 +11,18 @@ def starship_prompt():
# The `| cat` is a workaround for https://github.com/xonsh/xonsh/issues/3786. See https://github.com/starship/starship/pull/2807#discussion_r667316323.
return $(::STARSHIP:: prompt --status=@(status) --jobs=@(jobs) --cmd-duration=@(duration) | cat)
+def starship_rprompt():
+ last_cmd = __xonsh__.history[-1] if __xonsh__.history else None
+ status = last_cmd.rtn if last_cmd else 0
+ # I believe this is equivalent to xonsh.jobs.get_next_job_number() for our purposes,
+ # but we can't use that function because of https://gitter.im/xonsh/xonsh?at=60e8832d82dd9050f5e0c96a
+ jobs = sum(1 for job in __xonsh__.all_jobs.values() if job['obj'] and job['obj'].poll() is None)
+ duration = round((last_cmd.ts[1] - last_cmd.ts[0]) * 1000) if last_cmd else 0
+ # The `| cat` is a workaround for https://github.com/xonsh/xonsh/issues/3786. See https://github.com/starship/starship/pull/2807#discussion_r667316323.
+ return $(::STARSHIP:: prompt --status=@(status) --jobs=@(jobs) --cmd-duration=@(duration) --right | cat)
+
$PROMPT = starship_prompt
+$RIGHT_PROMPT = starship_rprompt
$STARSHIP_SHELL = "xonsh"
$STARSHIP_SESSION_KEY = uuid.uuid4().hex