Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Elm Section #528

Merged
merged 7 commits into from
Oct 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Spaceship is a minimalistic, powerful and extremely customizable [Zsh][zsh-url]
* Indicator for jobs in the background (``).
* Current Node.js version, through nvm/nodenv/n (``).
* Current Ruby version, through rvm/rbenv/chruby/asdf (`💎`).
* Current Elm version (`🌳`)
* Current Elixir version, through kiex/exenv/elixir (`💧`).
* Current Swift version, through swiftenv (`🐦`).
* Current Xcode version, through xenv (`🛠`).
Expand Down
12 changes: 12 additions & 0 deletions docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,18 @@ Ruby section is shown only in directories that contain `Gemfile`, or `Rakefile`,
| `SPACESHIP_RUBY_SYMBOL` | `💎·` | Character to be shown before Ruby version |
| `SPACESHIP_RUBY_COLOR` | `red` | Color of Ruby section |

### Elm (`elm`)

Elm section is shown only in directories that contain `elm.json` file, `elm-package.json` file, `elm-stuff` directory, or any other file with `.elm` extension.

| Variable | Default | Meaning |
| :------- | :-----: | ------- |
| `SPACESHIP_ELM_SHOW` | `true` | Show installed Elm version |
| `SPACESHIP_ELM_PREFIX` | `$SPACESHIP_PROMPT_DEFAULT_PREFIX` | Prefix before Elm section |
| `SPACESHIP_ELM_SUFFIX` | `$SPACESHIP_PROMPT_DEFAULT_SUFFIX` | Suffix after Elm section |
| `SPACESHIP_ELM_SYMBOL` | `🌳·` | Character to be shown before Elm version |
| `SPACESHIP_ELM_COLOR` | `cyan` | Color of Elm section |

### Elixir (`elixir`)

Elixir section is shown only in directories that contain `mix.exs`, or any other file with `.ex` or `.exs` extension. If the current elixir version is the same as the version set in `SPACESHIP_ELIXIR_DEFAULT_VERSION`, the elixir section will be hidden.
Expand Down
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* [Package version (package)](/docs/Options.md#package-version-package)
* [Node (node)](/docs/Options.md#nodejs-node)
* [Ruby (ruby)](/docs/Options.md#ruby-ruby)
* [Elm (elm)](/docs/Options.md#elm-elm)
* [Elixir (elixir)](/docs/Options.md#elixir-elixir)
* [Xcode (xcode)](/docs/Options.md#xcode-xcode)
* [Swift (swift)](/docs/Options.md#swift-swift)
Expand Down
36 changes: 36 additions & 0 deletions sections/elm.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#
# Elm
#
# A delightful language for reliable webapps.
# Link: https://elm-lang.org/

# ------------------------------------------------------------------------------
# Configuration
# ------------------------------------------------------------------------------

SPACESHIP_ELM_SHOW="${SPACESHIP_ELM_SHOW=true}"
SPACESHIP_ELM_PREFIX="${SPACESHIP_ELM_PREFIX="$SPACESHIP_PROMPT_DEFAULT_PREFIX"}"
SPACESHIP_ELM_SUFFIX="${SPACESHIP_ELM_SUFFIX="$SPACESHIP_PROMPT_DEFAULT_SUFFIX"}"
SPACESHIP_ELM_SYMBOL="${SPACESHIP_ELM_SYMBOL="🌳 "}"
SPACESHIP_ELM_COLOR="${SPACESHIP_ELM_COLOR="cyan"}"

# ------------------------------------------------------------------------------
# Section
# ------------------------------------------------------------------------------

# Show current version of Elm.
spaceship_elm() {
[[ $SPACESHIP_ELM_SHOW == false ]] && return

[[ -f elm.json || -f elm-package.json || -d elm-stuff || -n *.elm(#qN^/) ]] || return

spaceship::exists elm || return

local elm_version=$(elm --version 2> /dev/null)

spaceship::section \
"$SPACESHIP_ELM_COLOR" \
"$SPACESHIP_ELM_PREFIX" \
"${SPACESHIP_ELM_SYMBOL}v${elm_version}" \
"$SPACESHIP_ELM_SUFFIX"
}
1 change: 1 addition & 0 deletions spaceship.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ if [ -z "$SPACESHIP_PROMPT_ORDER" ]; then
package # Package version
node # Node.js section
ruby # Ruby section
elm # Elm section
elixir # Elixir section
xcode # Xcode section
swift # Swift section
Expand Down
136 changes: 136 additions & 0 deletions tests/elm.test.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#!/usr/bin/env zsh

# Required for shunit2 to run correctly
setopt shwordsplit
SHUNIT_PARENT=$0

# ------------------------------------------------------------------------------
# SHUNIT2 HOOKS
# ------------------------------------------------------------------------------

oneTimeSetUp() {
export TERM="xterm-256color"
export PATH=$PWD/tests/stubs:$PATH

SPACESHIP_PROMPT_FIRST_PREFIX_SHOW=true
SPACESHIP_PROMPT_ADD_NEWLINE=false
SPACESHIP_PROMPT_ORDER=(elm)

source spaceship.zsh
}

setUp() {
SPACESHIP_ELM_SHOW=true
SPACESHIP_ELM_PREFIX="via "
SPACESHIP_ELM_SUFFIX=""
SPACESHIP_ELM_SYMBOL="🌳 "
SPACESHIP_ELM_COLOR="cyan"

cd $SHUNIT_TMPDIR
touch test.elm
}

oneTimeTearDown() {
unset SPACESHIP_PROMPT_FIRST_PREFIX_SHOW
unset SPACESHIP_PROMPT_ADD_NEWLINE
unset SPACESHIP_PROMPT_ORDER
}

tearDown() {
unset SPACESHIP_ELM_SHOW
unset SPACESHIP_ELM_PREFIX
unset SPACESHIP_ELM_SUFFIX
unset SPACESHIP_ELM_SYMBOL
unset SPACESHIP_ELM_COLOR
}

# ------------------------------------------------------------------------------
# TEST CASES
# ------------------------------------------------------------------------------

test_elm() {
local expected="%{%B%}via %{%b%}%{%B%F{cyan}%}🌳 v0.20.0%{%b%f%}%{%B%}%{%b%}"
local actual="$(spaceship_prompt)"

assertEquals "render elm" "$expected" "$actual"
}

test_elm_show_false() {
SPACESHIP_ELM_SHOW=false

local expected=""
local actual="$(spaceship_prompt)"

assertEquals "don't render elm" "$expected" "$actual"
}

test_elm_files() {
local expected="%{%B%}via %{%b%}%{%B%F{cyan}%}🌳 v0.20.0%{%b%f%}%{%B%}%{%b%}"
local actual="$(spaceship_prompt)"

assertEquals "render elm when test.elm exists" "$expected" "$actual"

rm test.elm
touch elm.json

local actual="$(spaceship_prompt)"

assertEquals "render elm when elm.json exists" "$expected" "$actual"

rm elm.json
touch elm-package.json

local actual="$(spaceship_prompt)"

assertEquals "render elm when elm-package.json exists" "$expected" "$actual"

rm elm-package.json
mkdir elm-stuff

local actual="$(spaceship_prompt)"

assertEquals "render elm when elm-stuff exists" "$expected" "$actual"

rm -r elm-stuff

local expected=""
local actual="$(spaceship_prompt)"

assertEquals "don't render when no elm files are present" "$expected" "$actual"
}

test_elm_symbol() {
SPACESHIP_ELM_SYMBOL="🌵 "

local expected="%{%B%}via %{%b%}%{%B%F{cyan}%}🌵 v0.20.0%{%b%f%}%{%B%}%{%b%}"
local actual="$(spaceship_prompt)"

assertEquals "render elm with custom symbol" "$expected" "$actual"
}

test_elm_prefix() {
SPACESHIP_ELM_PREFIX='prefix'
SPACESHIP_ELM_SUFFIX=''

local expected="%{%B%}prefix%{%b%}%{%B%F{cyan}%}🌳 v0.20.0%{%b%f%}%{%B%}%{%b%}"
local actual="$(spaceship_prompt)"

assertEquals "render elm with prefix" "$expected" "$actual"
}

test_elm_suffix() {
SPACESHIP_ELM_PREFIX=''
SPACESHIP_ELM_SUFFIX='suffix'

local expected="%{%B%}%{%b%}%{%B%F{cyan}%}🌳 v0.20.0%{%b%f%}%{%B%}suffix%{%b%}"
local actual="$(spaceship_prompt)"

assertEquals "render elm with suffix" "$expected" "$actual"
}

# ------------------------------------------------------------------------------
# SHUNIT2
# Run tests with shunit2
# ------------------------------------------------------------------------------

source modules/shunit2/shunit2
3 changes: 3 additions & 0 deletions tests/stubs/elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env zsh

echo 0.20.0