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 /src | |
parent | 0af31238f66b34e268e404aaeb92008b72b5b49e (diff) |
feat(elvish): last command status (#3403)
Diffstat (limited to 'src')
-rw-r--r-- | src/init/starship.elv | 28 |
1 files changed, 22 insertions, 6 deletions
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 } |