-
-
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 module for showing exit codes of shell pipeline #370
Conversation
Oh no, I forgot about the quirk @lilyball talked about - when using |
I must admit, I'm a little confused by all of the configuration options - hopefully some new documentation could help with that? 🙂 This is just a thought - do you think there's value in modelling the display mode in an enum? For example:
|
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 taking the time to work on this @nrabulinski 🎉!
Everything looks great!
I just have one request: Please take a look at #367, and do the same here. It would be nice to be able to change the delimiters surrounding the exit codes.
I've already talked about it in the Discord server, but I don't personally think there's sense to add |
d7ada94
to
7892563
Compare
and a few smaller fixes one being changing delimeter_... to prefix/suffix as in starship#367
7892563
to
778d250
Compare
Judging from the name, |
@lilyball I just don’t see how it’d be different from my current |
Skimming the code, it looks like what you've actually implemented doesn't do what I thought it did. In fact, it doesn't even implement the behavior of showing an error on |
@lilyball It’d probably be much more viable to iterate through all the status codes in pipeline and show them when at least one of them errored which I might add with the next commit but as it is and considering what (at least I think) you’re talking about - it doesn’t make sense to add. |
@nrabulinski The whole point of my bash prompt status code setup is to convey the results of the previous job without extraneous info. The results include answering the question "is the status different from the pipestatus?" So basically, my prompt shows pipestatus, unless it's all zeroes. If pipestatus disagrees with status, it shows that disagreement parenthesized. And it colors the output accordingly, so Ultimately, I'm left with the shortest prompt that doesn't discard any status info. I can tell at a glance what both |
@nrabulinski Do you plan to make more changes to this PR or are we good to review as-is? |
@chipbuster I'll commit the changes @lilyball suggested in a day or two and then it should be ready to review |
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.
Looks good to me! 👍
Just seems you need to rerun the formatter.
If you can change the module to be disabled by default, we can go ahead and merge this.
Requesting review from another astronaut since this is a pretty big PR.
| `success_symbol` | "✔" | The symbol used if the exit code is equal to 0. | | ||
| `error_symbol` | "✖" | The symbol used if the exit code is non-zero. | | ||
| `simple_pipeline` | true | Show only one exit code if all values in the pipeline are equal. | | ||
| `disabled` | false | Disables the `status` module. | |
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.
Thinking it over, I think we should keep this module disabled
by default.
Could you please the configuration to reflect that?
None => vec![&exit_code], | ||
}; | ||
|
||
// kind of a hack to not show `<previous status code>` when a user sends ^C to clear the line |
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.
👍
let pipeline_error = pipestatus.iter().any(|&code| code != "0"); | ||
let mismatch = exit_code != *pipestatus.last()?; | ||
|
||
let display_mode = status_config.display_mode; //get_display_mode(&module); |
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.
Is this comment meant to be in the PR?
@@ -0,0 +1,209 @@ | |||
use ansi_term::Color; |
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.
Tests look great! 👍
Looks like rustfmt failed on....whitespace? Not entirely sure what happened there but hopefully it's easy to fix. |
It looks like the empty line has 2 stray spaces in it, which rustfmt wants to delete. |
I am still utterly confused by the fix 😅, but all tests are passing now! |
@nrabulinski A friendly reminder about those review comments. ☝️ |
"always" => DisplayMode::Always, | ||
"error" => DisplayMode::OnExitError, | ||
"any error" => DisplayMode::OnError, | ||
/*"mismatch" |*/ _ => DisplayMode::OnErrorOrMismatch, |
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.
Recommend explicitly matching "mismatch"
here, and panicking if it doesn't match one of those strings. Worst case, the panic is unreachable otherwise.
let pipestatus_arg = Arg::with_name("pipestatus") | ||
.long("pipestatus") | ||
.value_name("PIPESTATUS") | ||
.help("Status codes from the previous pipeline") |
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.
Recommend adding a long_help
here that documents the specific argument we're looking for. Is it a single, space-separated argument? Several individual arguments? Something else? If possible, I'd consider using Arg::multiple, which means that the expected format would be: --pipestatus 0 1 0 2
(as opposed to --pipestatus "0 1 0 2"
).
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.
Ah, that’s cool, I’m not really familiar with clap so I wasn’t aware this was a thing, thank you very much!
@@ -24,7 +24,7 @@ starship_preexec() { | |||
# Will be run before the prompt is drawn | |||
starship_precmd() { | |||
# Save the status, because commands in this pipeline will change $? | |||
STATUS=$? | |||
local STATUS=$? PIPE="${PIPESTATUS[@]}"; |
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.
It looks when using bash-preexec
this will have to be BP_PIPESTATUS
: https://github.com/rcaloras/bash-preexec/blob/master/bash-preexec.sh#L41-L45
Closing this in favor of a newer one: #1165 |
This MR is based on this one starship#370
This MR is based on this one starship#370
This MR is based on this one starship#370
This MR is based on this one starship#370
This MR is based on this one starship#370
This MR is based on this one starship#370
This MR is based on this one starship#370
This MR is based on this one starship#370
* feat: Add pipestatus display in status module This MR is based on this one #370 * Documentation * Add a test with map_symbol false * Handle bash preexec pipestatus * Add zsh support * Add fish support Thanks kidonng for the diff patch * Rename sucess_symbol to success_symbol
Description
I implemented
status
module which can show the exit code of the last command or all exit codes of the last pipelineMotivation and Context
Closes #193
Closes #882
Types of changes
Screenshots (if appropriate):
Default configuration:
![image](https://user-images.githubusercontent.com/24574288/64908926-c6b3ef00-d705-11e9-9dcc-db8a588bfa32.png)
![image](https://user-images.githubusercontent.com/24574288/64908944-f531ca00-d705-11e9-8a8d-b890b992adbf.png)
![image](https://user-images.githubusercontent.com/24574288/64908958-24483b80-d706-11e9-90ae-a55a9d5c57a6.png)
Symbols for exit codes:
No pipeline:
How Has This Been Tested?
Checklist: