From 87f3304dd79a9604bf5869b3682ac5fd12770106 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Sun, 7 Oct 2018 10:04:24 -0500 Subject: [PATCH 1/7] Add elm.zsh for elm version --- docs/Options.md | 12 ++++++++++++ sections/elm.zsh | 36 ++++++++++++++++++++++++++++++++++++ spaceship.zsh | 1 + 3 files changed, 49 insertions(+) create mode 100644 sections/elm.zsh diff --git a/docs/Options.md b/docs/Options.md index 19606f9e2..5abf5a625 100644 --- a/docs/Options.md +++ b/docs/Options.md @@ -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. diff --git a/sections/elm.zsh b/sections/elm.zsh new file mode 100644 index 000000000..0ffd735da --- /dev/null +++ b/sections/elm.zsh @@ -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" +} diff --git a/spaceship.zsh b/spaceship.zsh index e9e691be2..d18fa4ded 100644 --- a/spaceship.zsh +++ b/spaceship.zsh @@ -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 From e18191d4bae56ba8751e83bbb71f332e49c88120 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Wed, 10 Oct 2018 08:49:50 -0500 Subject: [PATCH 2/7] Add tests for elm --- tests/elm.test.zsh | 136 +++++++++++++++++++++++++++++++++++++++++++++ tests/stubs/elm | 3 + 2 files changed, 139 insertions(+) create mode 100755 tests/elm.test.zsh create mode 100755 tests/stubs/elm diff --git a/tests/elm.test.zsh b/tests/elm.test.zsh new file mode 100755 index 000000000..836b0d51b --- /dev/null +++ b/tests/elm.test.zsh @@ -0,0 +1,136 @@ +#!/usr/bin/env zsh +x + +# 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 diff --git a/tests/stubs/elm b/tests/stubs/elm new file mode 100755 index 000000000..ca837f404 --- /dev/null +++ b/tests/stubs/elm @@ -0,0 +1,3 @@ +#!/usr/bin/env zsh + +echo 0.20.0 \ No newline at end of file From 4700cb1317e14baec3e429fb251a9bbd5e47735f Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Wed, 10 Oct 2018 08:56:23 -0500 Subject: [PATCH 3/7] Add Elm to the list of features --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 1ed6d493e..bf825b131 100644 --- a/README.md +++ b/README.md @@ -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 (`๐Ÿ› `). From 42ad09801bd102612482d16162fb95aa0ce73064 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Sat, 13 Oct 2018 14:01:37 -0500 Subject: [PATCH 4/7] Remove +x option from test --- tests/elm.test.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/elm.test.zsh b/tests/elm.test.zsh index 836b0d51b..292a4450f 100755 --- a/tests/elm.test.zsh +++ b/tests/elm.test.zsh @@ -1,4 +1,4 @@ -#!/usr/bin/env zsh +x +#!/usr/bin/env zsh # Required for shunit2 to run correctly setopt shwordsplit From 950d8691a6d9df85cc51f879418a4f6057097132 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Sat, 13 Oct 2018 14:02:17 -0500 Subject: [PATCH 5/7] Add trailing newline --- tests/stubs/elm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/stubs/elm b/tests/stubs/elm index ca837f404..9f06f87d5 100755 --- a/tests/stubs/elm +++ b/tests/stubs/elm @@ -1,3 +1,3 @@ #!/usr/bin/env zsh -echo 0.20.0 \ No newline at end of file +echo 0.20.0 From f1bcf72fa46173c808bd2e69a73ef1119b1b7b6c Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Sat, 13 Oct 2018 14:12:21 -0500 Subject: [PATCH 6/7] Add Elm to README.md --- docs/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/README.md b/docs/README.md index a16c2901d..8aaaffcbd 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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) From 66123964d3c05a5bf9999c4525ffd6307e313953 Mon Sep 17 00:00:00 2001 From: Salmanul Farzy Date: Sun, 14 Oct 2018 01:04:57 +0530 Subject: [PATCH 7/7] Use $PWD variable instead of function call Signed-off-by: Salmanul Farzy --- tests/elm.test.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/elm.test.zsh b/tests/elm.test.zsh index 292a4450f..5e0cbd65c 100755 --- a/tests/elm.test.zsh +++ b/tests/elm.test.zsh @@ -10,7 +10,7 @@ SHUNIT_PARENT=$0 oneTimeSetUp() { export TERM="xterm-256color" - export PATH=$(pwd)/tests/stubs:$PATH + export PATH=$PWD/tests/stubs:$PATH SPACESHIP_PROMPT_FIRST_PREFIX_SHOW=true SPACESHIP_PROMPT_ADD_NEWLINE=false