feat(elvish): last command status (#3403)

This commit is contained in:
moko256 2022-01-07 06:00:38 +09:00 committed by GitHub
parent 0af31238f6
commit 500dc3ea6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 8 deletions

View File

@ -447,7 +447,7 @@ look at [this example](#with-custom-error-shape).
::: warning
`error_symbol` is not supported on elvish and nu shell.
`error_symbol` is not supported on nu shell.
:::
@ -2918,7 +2918,7 @@ To enable it, set `disabled` to `false` in your configuration file.
:::
::: warning
This module is not supported on elvish and nu shell.
This module is not supported on nu shell.
:::
### Options

View File

@ -1,17 +1,33 @@
set-env STARSHIP_SHELL "elvish"
set-env STARSHIP_SESSION_KEY (::STARSHIP:: session)
# Define Hooks
var cmd-status-code = 0
fn starship-after-command-hook {|m|
var error = $m[error]
if (is $error $nil) {
set cmd-status-code = 0
} else {
try {
set cmd-status-code = $error[reason][exit-status]
} except {
# The error is from the built-in commands and they have no status code.
set cmd-status-code = 1
}
}
}
# Install Hooks
set edit:after-command = [ $@edit:after-command $starship-after-command-hook~ ]
# Install starship
set edit:prompt = {
# Note:
# Elvish does not appear to support exit status codes (--status)
var cmd-duration = (printf "%.0f" (* $edit:command-duration 1000))
::STARSHIP:: prompt --jobs=$num-bg-jobs --cmd-duration=$cmd-duration
::STARSHIP:: prompt --jobs=$num-bg-jobs --cmd-duration=$cmd-duration --status $cmd-status-code
}
set edit:rprompt = {
# Note:
# Elvish does not appear to support exit status codes (--status)
var cmd-duration = (printf "%.0f" (* $edit:command-duration 1000))
::STARSHIP:: prompt --right --jobs=$num-bg-jobs --cmd-duration=$cmd-duration
::STARSHIP:: prompt --right --jobs=$num-bg-jobs --cmd-duration=$cmd-duration --status $cmd-status-code
}