Skip to content

Commit

Permalink
fix(elvish): upgrade shell integration for v0.17 (starship#3310)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkna authored Dec 30, 2021
1 parent 52abffa commit 67cddb6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 35 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ shown below. Can't see yours? Have a look at the [extra platform instructions](h

#### Elvish

**Warning** Only elvish v0.15 or higher is supported.
**Warning** Only elvish v0.17 or higher is supported.
Add the following to the end of `~/.elvish/rc.elv`:

```sh
Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ description: Starship is the minimal, blazing fast, and extremely customizable p
#### Elvish

::: warning
Only elvish v0.15 or higher is supported.
Only elvish v0.17 or higher is supported.
:::

Add the following to the end of `~/.elvish/rc.elv`:
Expand Down
2 changes: 1 addition & 1 deletion install/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ print_install() {
# shellcheck disable=SC2088
config_file="~/.elvish/rc.elv"
config_cmd="eval (starship init elvish)"
warning="${warning} Only elvish v0.15 or higher is supported."
warning="${warning} Only elvish v0.17 or higher is supported."
;;
nushell )
# shellcheck disable=SC2088
Expand Down
38 changes: 6 additions & 32 deletions src/init/starship.elv
Original file line number Diff line number Diff line change
@@ -1,43 +1,17 @@
set-env STARSHIP_SHELL "elvish"
set-env STARSHIP_SESSION_KEY (::STARSHIP:: session)

# Define Hooks
local:cmd-start-time = 0
local:cmd-end-time = 0
local:cmd-duration = 0

fn starship-after-readline-hook [line]{
cmd-start-time = (::STARSHIP:: time)
}

fn starship-before-readline-hook {
cmd-end-time = (::STARSHIP:: time)
cmd-duration = (- $cmd-end-time $cmd-start-time)
}

# Install Hooks
edit:after-readline = [ $@edit:after-readline $starship-after-readline-hook~ ]
edit:before-readline = [ $@edit:before-readline $starship-before-readline-hook~ ]

# Install starship
edit:prompt = {
set edit:prompt = {
# Note:
# Elvish does not appear to support exit status codes (--status)

if (== $cmd-start-time 0) {
::STARSHIP:: prompt --jobs=$num-bg-jobs
} else {
::STARSHIP:: prompt --jobs=$num-bg-jobs --cmd-duration=$cmd-duration
}
var cmd-duration = (printf "%.0f" (* $edit:command-duration 1000))
::STARSHIP:: prompt --jobs=$num-bg-jobs --cmd-duration=$cmd-duration
}

edit:rprompt = {
set edit:rprompt = {
# Note:
# Elvish does not appear to support exit status codes (--status)

if (== $cmd-start-time 0) {
::STARSHIP:: prompt --right --jobs=$num-bg-jobs
} else {
::STARSHIP:: prompt --right --jobs=$num-bg-jobs --cmd-duration=$cmd-duration
}
var cmd-duration = (printf "%.0f" (* $edit:command-duration 1000))
::STARSHIP:: prompt --right --jobs=$num-bg-jobs --cmd-duration=$cmd-duration
}

0 comments on commit 67cddb6

Please sign in to comment.