-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
fix(bash): last command status and command duration #1185
Conversation
eval "$(starship init bash)"
export PROMPT_COMMAND="starship_precmd;${PROMPT_COMMAND/starship_precmd;/}"
This workaround broke the "command duration" module. |
This breaks command duration for me as idle time become counted as well. |
Strange. The workaround works fine. But the change in this PR breaks command duration. 🤔 @X-dark can you confirm if the workaround (without the change in this PR) works for you? |
Sorry I have tested the workaround, not the PR. Without any fix or workaround, my PROMPT_COMMAND looks like this:
|
Thanks @X-dark . I've updated the PR to handle those cases. |
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.
LGTM. This is really quite a clever solution, and simple to implement. Well done!
# add multiple instances of the starship function and keep other user functions if any. | ||
if [[ -z "$PROMPT_COMMAND" ]]; then | ||
PROMPT_COMMAND="starship_precmd" | ||
elif [[ "$PROMPT_COMMAND" != *"starship_precmd" ]]; then | ||
# Remove any trailing semicolon before appending (PR #784) | ||
PROMPT_COMMAND="${PROMPT_COMMAND%;};starship_precmd;" | ||
# Appending to PROMPT_COMMAND breaks exit status ($?) checking. |
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.
Thanks for the comment here--will really help in the future.
I have to speak frankly here for a second: the number of hoops we've jumped through on this project to try to get things working perfectly in Bash is starting to get ludicrous. First we set, then we appended, then we prepended. We've changed separators between semicolons and whitespace, we've had to deal with other shell helpers breaking starship with their own initscripts. Every single time, I've been optimistic that this change will finally fix everything, and every time, I've been proven wrong. And judging by the number of conflicts we've gotten with other shell frameworks, I'm not sure they're doing much better than us. I certainly hope that this will fix our problems once and for all (and looking at it, I do think it will!), but in the event that I'm proven wrong again, I'm going to have to suggest that we push that responsibility on the user in one of two ways:
|
* fix: character module last command status for bash * fix: command duration module for bash
Description
For bash,
Appending
starship_precmd
toPROMPT_COMMAND
breaks previous command's status ($?
) checking when other commands already exist inPROMPT_COMMAND
. Because those commands can modify the actual$?
variable.Prepending
starship_precmd
toPROMPT_COMMAND
breaks command duration module when other commans already exist inPROMPT_COMMAND
. Because those commands can trigger setting theSTARSHIP_START_TIME
variable.So, to fix those cases, existing
PROMPT_COMMAND
is preserved in_PRESERVED_PROMPT_COMMAND
variable which is later executed inside thestarship_precmd
function.Note: nojhan/liquidprompt also does the same thing.
Motivation and Context
Related to #954, which was closed without solving the underlying issue that caused it.
Types of changes
Screenshots (if appropriate):
How Has This Been Tested?
Checklist: