diff options
author | moko256 <koutaro.mo@gmail.com> | 2022-01-07 06:00:38 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-06 22:00:38 +0100 |
commit | 500dc3ea6e2989a6a9e8b9960a8e9d7aa44d559d (patch) | |
tree | ac59cf97e51230349b28f019d8d3d9d79338ed59 | |
parent | 0af31238f66b34e268e404aaeb92008b72b5b49e (diff) |
feat(elvish): last command status (#3403)
-rw-r--r-- | docs/config/README.md | 4 | ||||
-rw-r--r-- | src/init/starship.elv | 28 |
2 files changed, 24 insertions, 8 deletions
diff --git a/docs/config/README.md b/docs/config/README.md index 93d32c89d..4ee5c4639 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -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 diff --git a/src/init/starship.elv b/src/init/starship.elv index d9552be84..3b0234878 100644 --- a/src/init/starship.elv +++ b/src/init/starship.elv @@ -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 } |