Created
January 12, 2022 21:08
-
-
Save krader1961/615003e1527950b84a9eef9a45ebcb08 to your computer and use it in GitHub Desktop.
My Elvish prompt module. Invoked from rc.elv as `use prompt; prompt:main &use-git=true`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use util | |
use github.com/krader1961/elvish-lib/cmd-duration | |
use github.com/zzamboni/elvish-themes/chain | |
fn main {|&use-git=$false| | |
set chain:prompt-segment-delimiters = [" " " "] # space on each side of a segment | |
set chain:bold-prompt = $false | |
set chain:glyph[chain] = "" | |
set chain:segment[arrow] = { | |
# put (styled " >" bg-bright-cyan)" " | |
put (styled " > " default) | |
} | |
set chain:segment-style[dir] = [bg-bright-green fg-black] | |
set chain:segment-style[git-branch] = [bg-bright-magenta fg-black] | |
set chain:segment-style[chain] = [default] | |
set chain:segment-style[arrow] = [bg-bright-cyan] | |
set chain:segment-style[conda-env] = [bg-'#EEEEEE' fg-magenta] | |
set chain:segment-style[machname] = [bg-'#EEDDCC' fg-black] | |
set chain:segment-style[cmd-duration] = [bg-bright-cyan fg-black] | |
set chain:segment-style[shlvl] = [bg-bright-yellow fg-black] | |
# This is the default prompt definition but with the addition of a segment to | |
# report whether I have activated an Anaconda environment. | |
fn conda-segment {|| | |
if (not (eq "" $E:CONDA_DEFAULT_ENV)) { | |
chain:prompt-segment conda-env $E:CONDA_DEFAULT_ENV | |
} | |
} | |
# Cache the machine name. It's cheap to retrieve but why pay the cost? | |
var _machname = (util:machname) | |
fn machname-segment {|| | |
chain:prompt-segment machname $_machname | |
} | |
# The right prompt reports how long the previous command ran and whether we're | |
# in a nested shell. | |
fn shlvl-segment {|| | |
if (!= $E:SHLVL 1) { | |
chain:prompt-segment shlvl "SHLVL "$E:SHLVL | |
} | |
} | |
fn cmd-duration-segment {|| | |
chain:prompt-segment cmd-duration (cmd-duration:human-readable $edit:command-duration) | |
} | |
if $use-git { | |
set chain:prompt-segments = [ | |
su $machname-segment~ $conda-segment~ dir git-branch git-combined arrow | |
] | |
} else { | |
set chain:prompt-segments = [ | |
su $machname-segment~ $conda-segment~ dir arrow | |
] | |
} | |
set chain:rprompt-segments = [ $shlvl-segment~ $cmd-duration-segment~ ] | |
chain:init | |
set edit:rprompt-persistent = $true | |
set edit:prompt-stale-transform = {|x| styled $x "bg-bright-yellow" } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment