-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add support for xonsh #2807
Changes from 7 commits
f19b1b8
d673c43
edae13b
b7984ca
1c21b3b
425949c
ab94a7c
e9e406f
57ea974
1e0bc8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import random | ||
import string | ||
|
||
|
||
def starship_prompt(): | ||
last_cmd = __xonsh__.history[-1] if __xonsh__.history else None | ||
status = last_cmd.rtn if last_cmd else 0 | ||
jobs = len(__xonsh__.all_jobs) | ||
duration = round((last_cmd.ts[1] - last_cmd.ts[0]) * 1000) if last_cmd else 0 | ||
return $(::STARSHIP:: prompt --status=@(status) --jobs=@(jobs) --cmd-duration=@(duration)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems to work for me when using https://github.com/anki-code/xontrib-prompt-starship latest and
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, @davidkna. This was fixed upstream in xonsh just three weeks ago: xonsh/xonsh#4336 But since no released versions of xonsh contain that fix, we should probably work around it here. I've added a workaround: 1e0bc8d |
||
|
||
|
||
$PROMPT = starship_prompt | ||
$STARSHIP_SHELL = "xonsh" | ||
$STARSHIP_SESSION_KEY = "".join(random.choice(string.ascii_letters + string.digits) for _ in range(16)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm getting a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reproduced on my end. I'm pretty confused by xonsh's behavior here. I've reduced some of the surprising behavior to a minimal example and asked about it on the xonsh gitter: https://gitter.im/xonsh/xonsh?at=60e7d763951c58084ecb7108 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a work around you could use the uuid module from the python std library. I think this would be enough we just need a unique id for each session srt(uuid.uuid4())
# or
uuid.uuid4().hex There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Thanks for that suggestion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After running any command the jobs will sometimes display for me, with only the starship init in my
.xonshrc
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Getting job accounting right in xonsh apparently requires regularly calling
_clear_dead_jobs
.We could accomplish that here by calling
get_next_job_number
. In fact, #1265 did exactly that.Unfortunately, due to what I believe is the same issue as above, we're pretty limited here: we can't use any imported functions or even any names we define outside of this function. As a workaround, I've duplicated enough of the relevant logic in
_clear_dead_jobs
to ignore dead jobs in our count here.Incidentally, I reproduced this on xonsh 0.9.27 but not on xonsh's latest main branch. But I don't understand why they would be different. 🤷🏻♂️