Giter VIP home page Giter VIP logo

elvish-themes's Introduction

Elvish themes

This package contains Elvish themes I have developed. Install it using epm:

use epm
epm:install github.com/zzamboni/elvish-themes

Please note: These modules are only guaranteed to be fully compatible with Elvish HEAD, which is what I use. This means that occasionally, they will not work even with the latest official release, when breaking changes are introduced. Since Elvish is in active development, I highly recommend you use the latest commit too.

Currently the following themes are included:

chain

Chain prompt theme, based on the fish theme at https://github.com/oh-my-fish/theme-chain.

See the install and use instructions in chain.org.

elvish-themes's People

Contributors

artemt avatar zzamboni avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

elvish-themes's Issues

Chain theme errors with Elvish 0.13 with default prompts

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.

Two races in the chain theme

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 = ""

Timestamp segment in chain theme defaults to grey which is no longer valid

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

Bug in fn prompt-segment

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:

elvish-themes/chain.elv

Lines 105 to 110 in 1010ade

if (has-key $default-segment-style $segment-or-style) {
style = (-segment-style $segment-or-style)
}
if (has-key $default-glyph $segment-or-style) {
texts = [ (-glyph $segment-or-style) $@texts ]
}

Add feature for modifying function prompt-segment output

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.

Error using chain theme: variable $nil not found

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.