zzamboni / elvish-themes Goto Github PK
View Code? Open in Web Editor NEWPrompt themes for Elvish
License: MIT License
Prompt themes for Elvish
License: MIT License
Starship now can visualise the exit code, and it would be nice (not essential) to have this in Chain too, thank you!
I implemented support for my Anaconda virtual environment management functions. That involved modifying my prompt to insert a lambda into chain:prompt-segments
:
# 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
}
}
chain:prompt-segments = [
su $conda-segment~ dir git-branch git-combined arrow
]
I added agit-branch
key to my definition of the chain:segment-style
map. However, that results in an exception because that segment-style isn't defined by chain:default-segment-style
. The bug is that this line should use $segment-style
rather than $default-segment-style
and $glyph
rather than $default-glyph
:
Lines 105 to 110 in 1010ade
https://github.com/zzamboni/elvish-themes/blob/master/chain.elv#L196
tmp
is now a reserved keyword: elves/elvish@973fe39
Following the instructions to load the chain theme fails in a clean elvish shell:
~> use github.com/zzamboni/elvish-themes/chain
Exception: Compilation error: variable $nil not found
/Users/daniel/.elvish/lib/github.com/zzamboni/elvish-themes/chain.elv, line 125: if (not-eq $branch $nil) {
[tty], line 1: use github.com/zzamboni/elvish-themes/chain
This is in Elvish version 0.12 installed from Homebrew on macOS. The shell has not been initialized beyond the instructions found in this repo.
To reproduce:
~> ls -la ~/.elvish
total 0
drwx------ 2 daniel staff 64 Aug 24 02:42 .
drwxr-xr-x+ 68 daniel staff 2176 Aug 24 02:42 ..
~> use epm
~> epm:install github.com/zzamboni/elvish-themes
=> Installing github.com/zzamboni/elvish-themes
Cloning into '/Users/daniel/.elvish/lib/github.com/zzamboni/elvish-themes'...
remote: Enumerating objects: 202, done.
remote: Total 202 (delta 0), reused 0 (delta 0), pack-reused 202
Receiving objects: 100% (202/202), 63.68 KiB | 749.00 KiB/s, done.
Resolving deltas: 100% (98/98), done.
=> Installing dependencies: github.com/href/elvish-gitstatus
=> Installing github.com/href/elvish-gitstatus
Cloning into '/Users/daniel/.elvish/lib/github.com/href/elvish-gitstatus'...
remote: Enumerating objects: 30, done.
remote: Counting objects: 100% (30/30), done.
remote: Compressing objects: 100% (24/24), done.
remote: Total 30 (delta 10), reused 26 (delta 6), pack-reused 0
Unpacking objects: 100% (30/30), done.
~> use github.com/zzamboni/elvish-themes/chain
Exception: Compilation error: variable $nil not found
/Users/daniel/.elvish/lib/github.com/zzamboni/elvish-themes/chain.elv, line 125: if (not-eq $branch $nil) {
[tty], line 1: use github.com/zzamboni/elvish-themes/chain
By default the timestamp
segment is set to be colored as "grey" as per this line https://github.com/zzamboni/elvish-themes/blob/master/chain.elv#L45 but with Elvish 0.13 (and presumably going forward) "grey" is no longer a valid color for styled
command:
[/u/h/v/ports]─[⎇ master]─> styled "this message should be red" red
▶ (styled (styled-segment this message should be red &fg-color=<unknown red> &bg-color=$nil))
[/u/h/v/ports]─[⎇ master]─> styled "this message should be grey" grey
Exception: grey is not a valid style transformer
The default color for this segment should be updated to be one of the other valid colors, probably "bright-black" instead as that is the closest parallel per the release notes https://elv.sh/blog/0.13-release-notes.html
I find a prompt with spaces around the segments (imagine the segments being colored differently), ~/p/3/elvish ⎇ min-max-functions >
, easier to read compared to brackets, [~/p/3/elvish][⎇ min-max-functions]>
. Any chance you would entertain adding a var, such as chain:segment-brackets = $true
, that fn prompt-segment
can check for whether to use brackets or spaces. I don't think there is much value in making each char individually configurable as there is really only one other sensible option, {segment}
, if you ignore non-ASCII characters.
Hi,
the chain.org/elv code looks like a good starting point to write a personal theme so a open licence would be helpful.
Note that the left and right prompts are rendered in parallel in separate goroutines. This causes two data races in the chain theme.
The first is in the gitstatus:query
function which starts gitstatusd
if it isn't already running. Since gitstatus:query
is always run in both prompts via the chain:-parse-git
function both prompts can decide that the daemon isn't running and start it. One of those daemons will die almost immediately resulting in this error appearing in the terminal:
job (external $binary) \ WTF
--num-threads=(thread-count) \
--max-num-staged=$E:GITSTATUS_MAX_NUM_STAGED\
--max-num-unstaged=$E:GITSTATUS_MAX_NUM_UNSTAGED\
--max-num-untracked=$E:GITSTATUS_MAX_NUM_UNTRACKED\
--max-num-conflicted=$E:GITSTATUS_MAX_NUM_CONFLICTED\
< $state[stdin] \
> $state[stdout] \
2> /dev/null & finished
The fix is to call gitstatus:start
right after the use github.com/href/elvish-gitstatus/gitstatus
statement.
The second race is due to always calling chain:-git-parse
even if the prompt does not contain any git segments. That can cause the left and right prompts to read from the gitstatusd
pipe at the same time. Resulting in stochastic exceptions. Properly fixing this will require an Elvish mutex that can be used to protect critical sections. Or a major redesign of the chain module to ensure -git-parse
is only run once whenever prompts are rendered. A partial fix is to call -git-parse
only if the prompt contains at least one git segment. That is probably "good enough" since people won't normally put git information in both prompts. This is what my copy of chain:-build-chain
looks like:
fn -build-chain [segments]{
if (eq $segments []) {
return
}
for seg $segments {
if (str:has-prefix (to-string $seg) "git-") {
-parse-git
break
}
}
first = $true
output = ""
Using commit 5cd2d7c with Elvish v0.13 and the default prompts (both left and right). Example below where I originally launch the shell without the theme then call use
to try to load it:
/usr/home/vendion> use github.com/zzamboni/elvish-themes/chain
/usr/home/vendion> read: Illegal option -d
prompt function error: sh exited with 2
(prompt here but not rendered)
read: Illegal option -d
prompt function error: sh exited with 2
(prompt here but not rendered)
I have even tried to manually define the segmants for the left and right prompts with the following and still get the same error:
chain:prompt-segments = [ su dir git-branch git-combined arrow ]
chain:rprompt-segments = [ (constantly (styled (whoami)✸(hostname) inverse)) timestamp ]
but I still get the same error as above.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.