summaryrefslogtreecommitdiffstats
path: root/src/init/starship.elv
blob: 1b84632a82330ce31f8978093a931a25983bf34a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
set-env STARSHIP_SHELL "elvish"
set-env STARSHIP_SESSION_KEY (::STARSHIP:: session)

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

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

fn starship-before-readline-hook {
    cmd-end-time = (::STARSHIP:: 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 = {
    # 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-end-time $cmd-start-time)
    }
}

# Get rid of default rprompt
edit:rprompt = { }