From 9cb48ea6ea428dcb327cbbf3cdc876abbc281792 Mon Sep 17 00:00:00 2001 From: Brad Date: Wed, 19 Jun 2019 06:49:37 -0400 Subject: [PATCH] feat: Add elixir section (#190) --- .all-contributorsrc | 9 +++ README.md | 3 +- docs/Options.md | 13 ++++ docs/README.md | 1 + fish_prompt.fish | 2 +- functions/__sf_section_elixir.fish | 57 ++++++++++++++ package.json | 32 +++++--- tests/__sf_section_elixir.test.fish | 110 ++++++++++++++++++++++++++++ 8 files changed, 216 insertions(+), 11 deletions(-) create mode 100644 functions/__sf_section_elixir.fish create mode 100644 tests/__sf_section_elixir.test.fish diff --git a/.all-contributorsrc b/.all-contributorsrc index b6ec365..ed715bb 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -201,6 +201,15 @@ "doc" ] }, + { + "login": "bradcypert", + "name": "Brad", + "avatar_url": "https://avatars0.githubusercontent.com/u/1455979?v=4", + "profile": "http://www.bradcypert.com", + "contributions": [ + "code" + ] + }, { "login": "nammn", "name": "Nam Nguyen", diff --git a/README.md b/README.md index fefda4b..f95c436 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,7 @@ Spacefish is a minimalistic, powerful and extremely customizable
Matan Kushner](https://twitter.com/matchai)
[馃悰](https://github.com/matchai/spacefish/issues?q=author%3Amatchai "Bug reports") [馃捇](https://github.com/matchai/spacefish/commits?author=matchai "Code") [馃摉](https://github.com/matchai/spacefish/commits?author=matchai "Documentation") [馃憖](#review-matchai "Reviewed Pull Requests") [鈿狅笍](https://github.com/matchai/spacefish/commits?author=matchai "Tests") [馃敡](#tool-matchai "Tools") [馃帹](#design-matchai "Design") | [
Tiffany Le-Nguyen](https://github.com/sirMerr)
[馃悰](https://github.com/matchai/spacefish/issues?q=author%3AsirMerr "Bug reports") [馃捇](https://github.com/matchai/spacefish/commits?author=sirMerr "Code") [馃摉](https://github.com/matchai/spacefish/commits?author=sirMerr "Documentation") [馃憖](#review-sirMerr "Reviewed Pull Requests") [鈿狅笍](https://github.com/matchai/spacefish/commits?author=sirMerr "Tests") | [
Snuggle](https://github.com/Snuggle)
[馃悰](https://github.com/matchai/spacefish/issues?q=author%3ASnuggle "Bug reports") [馃捇](https://github.com/matchai/spacefish/commits?author=Snuggle "Code") [馃摉](https://github.com/matchai/spacefish/commits?author=Snuggle "Documentation") [馃憖](#review-Snuggle "Reviewed Pull Requests") [鈿狅笍](https://github.com/matchai/spacefish/commits?author=Snuggle "Tests") | [
Jaskaran Bindra](https://github.com/jskrnbindra)
[馃捇](https://github.com/matchai/spacefish/commits?author=jskrnbindra "Code") [馃摉](https://github.com/matchai/spacefish/commits?author=jskrnbindra "Documentation") [鈿狅笍](https://github.com/matchai/spacefish/commits?author=jskrnbindra "Tests") | [
Konstantin Labun](https://labun.me)
[馃捇](https://github.com/matchai/spacefish/commits?author=kulabun "Code") [馃摉](https://github.com/matchai/spacefish/commits?author=kulabun "Documentation") [鈿狅笍](https://github.com/matchai/spacefish/commits?author=kulabun "Tests") | [
Kyle Holzinger](https://medium.com/@kyleholzinger)
[馃捇](https://github.com/matchai/spacefish/commits?author=kyleholzinger "Code") [馃摉](https://github.com/matchai/spacefish/commits?author=kyleholzinger "Documentation") | [
Salmanul Farzy](https://github.com/salmanulfarzy)
[馃捇](https://github.com/matchai/spacefish/commits?author=salmanulfarzy "Code") [馃憖](#review-salmanulfarzy "Reviewed Pull Requests") | | :---: | :---: | :---: | :---: | :---: | :---: | :---: | | [
owais](https://owais.lone.pw)
[馃捇](https://github.com/matchai/spacefish/commits?author=owais "Code") [馃摉](https://github.com/matchai/spacefish/commits?author=owais "Documentation") [鈿狅笍](https://github.com/matchai/spacefish/commits?author=owais "Tests") | [
Samantha Enders](https://github.com/ladysamantha)
[馃捇](https://github.com/matchai/spacefish/commits?author=ladysamantha "Code") [馃摉](https://github.com/matchai/spacefish/commits?author=ladysamantha "Documentation") [鈿狅笍](https://github.com/matchai/spacefish/commits?author=ladysamantha "Tests") | [
Evan Relf](https://evanrelf.com)
[馃捇](https://github.com/matchai/spacefish/commits?author=evanrelf "Code") [馃摉](https://github.com/matchai/spacefish/commits?author=evanrelf "Documentation") | [
Jason Etcovitch](https://jasonet.co)
[馃捇](https://github.com/matchai/spacefish/commits?author=JasonEtco "Code") [馃摉](https://github.com/matchai/spacefish/commits?author=JasonEtco "Documentation") | [
hrvoj3e](https://github.com/hrvoj3e)
[馃悰](https://github.com/matchai/spacefish/issues?q=author%3Ahrvoj3e "Bug reports") [馃捇](https://github.com/matchai/spacefish/commits?author=hrvoj3e "Code") | [
Michael Newman](http://newmaniese.com)
[馃悰](https://github.com/matchai/spacefish/issues?q=author%3Anewmaniese "Bug reports") [馃捇](https://github.com/matchai/spacefish/commits?author=newmaniese "Code") [馃摉](https://github.com/matchai/spacefish/commits?author=newmaniese "Documentation") [鈿狅笍](https://github.com/matchai/spacefish/commits?author=newmaniese "Tests") | [
Konrad](https://github.com/k-lyda)
[馃悰](https://github.com/matchai/spacefish/issues?q=author%3Ak-lyda "Bug reports") | -| [
Will Neville](https://github.com/dubnev)
[馃悰](https://github.com/matchai/spacefish/issues?q=author%3Adubnev "Bug reports") | [
Daniel Trautmann](https://github.com/danieltrautmann)
[馃捇](https://github.com/matchai/spacefish/commits?author=danieltrautmann "Code") | [
Jonas 脰hlander](https://github.com/Menturan)
[馃悰](https://github.com/matchai/spacefish/issues?q=author%3AMenturan "Bug reports") | [
lindsay](https://twitter.com/lynzt)
[馃摉](https://github.com/matchai/spacefish/commits?author=lynzt "Documentation") | [
Nam Nguyen](https://github.com/nammn)
[馃捇](https://github.com/matchai/spacefish/commits?author=nammn "Code") | +| [
Will Neville](https://github.com/dubnev)
[馃悰](https://github.com/matchai/spacefish/issues?q=author%3Adubnev "Bug reports") | [
Daniel Trautmann](https://github.com/danieltrautmann)
[馃捇](https://github.com/matchai/spacefish/commits?author=danieltrautmann "Code") | [
Jonas 脰hlander](https://github.com/Menturan)
[馃悰](https://github.com/matchai/spacefish/issues?q=author%3AMenturan "Bug reports") | [
lindsay](https://twitter.com/lynzt)
[馃摉](https://github.com/matchai/spacefish/commits?author=lynzt "Documentation") | [
Nam Nguyen](https://github.com/nammn)
[馃捇](https://github.com/matchai/spacefish/commits?author=nammn "Code") | [
Brad](http://www.bradcypert.com)
[馃捇](https://github.com/matchai/spacefish/commits?author=bradcypert "Code") | This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome! diff --git a/docs/Options.md b/docs/Options.md index ef7d6a6..470dbc3 100644 --- a/docs/Options.md +++ b/docs/Options.md @@ -259,6 +259,19 @@ Conda section is shown when ```conda``` is installed and $CONDA_DEFAULT_ENV is s | `SPACEFISH_CONDA_SYMBOL` | `馃厭路` | Character to be shown before Conda version | | `SPACEFISH_CONDA_COLOR` | `blue` | Color of Conda section | + +### Elixir \(`elixir`\) + +Elixir section is shown when ```mix.exs``` is found or elixir files are found and either kiex, exenv, elixir is avaiable on your path. + +| Variable | Default | Meaning | +| :------- | :-----: | ------- | +| `SPACESHIP_ELIXIR_SHOW` | `true` | Show current Elixir version | +| `SPACEFISH_ELIXIR_PREFIX` | `$SPACEFISH_PROMPT_DEFAULT_PREFIX` | Prefix before the elixir section | +| `SPACEFISH_ELIXIR_SUFFIX` | `$SPACEFISH_PROMPT_DEFAULT_SUFFIX` | Suffix after the elixir section | +| `SPACEFISH_ELIXIR_SYMBOL` | `馃挧路` | Character to be shown before Elixir version | +| `SPACEFISH_ELIXIR_COLOR` | `magenta` | Color of Elixir section | + ### Pyenv \(`pyenv`\) Pyenv section is shown only in directories that contain `.python-version`, `requirements.txt`, `pyproject.toml`, or any other file with `.py` extension. diff --git a/docs/README.md b/docs/README.md index e850f91..ca58102 100644 --- a/docs/README.md +++ b/docs/README.md @@ -18,6 +18,7 @@ * [Ruby (ruby)](./docs/Options.md#ruby-ruby) * [Haskell (haskell)](./docs/Options.md#haskell-haskell) * [Conda (conda)](./docs/Options.md#conda-conda) + * [Elixir (elixir)](./docs/Options.md#elixir-elixir) * [Amazon Web Services (aws)](./docs/Options.md#amazon-web-services-aws-aws) * [Pyenv (pyenv)](./docs/Options.md#pyenv-pyenv) * [Go (golang)](./docs/Options.md#go-golang) diff --git a/fish_prompt.fish b/fish_prompt.fish index 277da34..80d4d51 100644 --- a/fish_prompt.fish +++ b/fish_prompt.fish @@ -13,7 +13,7 @@ function fish_prompt __sf_util_set_default SPACEFISH_PROMPT_SUFFIXES_SHOW true __sf_util_set_default SPACEFISH_PROMPT_DEFAULT_PREFIX "via " __sf_util_set_default SPACEFISH_PROMPT_DEFAULT_SUFFIX " " - __sf_util_set_default SPACEFISH_PROMPT_ORDER time user dir host git package node ruby golang php rust haskell julia docker aws venv conda pyenv dotnet kubecontext exec_time line_sep battery vi_mode jobs exit_code char + __sf_util_set_default SPACEFISH_PROMPT_ORDER time user dir host git package node ruby golang php rust haskell julia elixir docker aws venv conda pyenv dotnet kubecontext exec_time line_sep battery vi_mode jobs exit_code char # ------------------------------------------------------------------------------ # Sections diff --git a/functions/__sf_section_elixir.fish b/functions/__sf_section_elixir.fish new file mode 100644 index 0000000..13468b0 --- /dev/null +++ b/functions/__sf_section_elixir.fish @@ -0,0 +1,57 @@ +# +# Elixir +# +# A dynamic, reflective, object-oriented, general-purpose programming language. +# Link: https://www.elixir-lang.org/ + +function __sf_section_elixir -d "Show current version of Elixir" + # ------------------------------------------------------------------------------ + # Configuration + # ------------------------------------------------------------------------------ + + __sf_util_set_default SPACEFISH_ELIXIR_SHOW true + __sf_util_set_default SPACEFISH_ELIXIR_PREFIX $SPACEFISH_PROMPT_DEFAULT_PREFIX + __sf_util_set_default SPACEFISH_ELIXIR_SUFFIX $SPACEFISH_PROMPT_DEFAULT_SUFFIX + __sf_util_set_default SPACEFISH_ELIXIR_SYMBOL "馃挧 " + __sf_util_set_default SPACEFISH_ELIXIR_DEFAULT_VERSION $SPACEFISH_ELIXIR_DEFAULT_VERSION + __sf_util_set_default SPACEFISH_ELIXIR_COLOR magenta + + # ------------------------------------------------------------------------------ + # Section + # ------------------------------------------------------------------------------ + + # Check if that user wants to show elixir version + [ $SPACEFISH_ELIXIR_SHOW = false ]; and return + + # Show versions only for Elixir-specific folders + if not test -f mix.exs \ + -o (count *.ex) -gt 0 \ + -o (count *.exs) -gt 0 + return + end + + set -l elixir_version + + if type -q kiex + set elixir_version $ELIXIR_VERSION + else if type -q exenv + set elixir_version (exenv version-name) + else if type -q elixir + set elixir_version (elixir -v 2>/dev/null | string match -r "Elixir.*" | string split " ")[2] + else + return + end + + [ -z "$elixir_version" -o "$elixir_version" = "system" ]; and return + + # Add 'v' before elixir version that starts with a number + if test -n (echo (string match -r "^[0-9].+\$" "$elixir_version")) + set elixir_version "v$elixir_version" + end + + __sf_lib_section \ + $SPACEFISH_ELIXIR_COLOR \ + $SPACEFISH_ELIXIR_PREFIX \ + "$SPACEFISH_ELIXIR_SYMBOL""$elixir_version" \ + $SPACEFISH_ELIXIR_SUFFIX +end diff --git a/package.json b/package.json index 0fcd1da..c65e1cf 100644 --- a/package.json +++ b/package.json @@ -25,15 +25,29 @@ "@semantic-release/commit-analyzer", "@semantic-release/release-notes-generator", "@semantic-release/changelog", - ["@semantic-release/exec", { - "prepareCmd": "./scripts/version.sh ${nextRelease.version}" - }], - ["@semantic-release/git", { - "assets": ["CHANGELOG.md", "fish_prompt.fish"] - }], - ["@semantic-release/github", { - "releasedLabels": ["Status: Released"] - }] + [ + "@semantic-release/exec", + { + "prepareCmd": "./scripts/version.sh ${nextRelease.version}" + } + ], + [ + "@semantic-release/git", + { + "assets": [ + "CHANGELOG.md", + "fish_prompt.fish" + ] + } + ], + [ + "@semantic-release/github", + { + "releasedLabels": [ + "Status: Released" + ] + } + ] ] } } diff --git a/tests/__sf_section_elixir.test.fish b/tests/__sf_section_elixir.test.fish new file mode 100644 index 0000000..5c411f2 --- /dev/null +++ b/tests/__sf_section_elixir.test.fish @@ -0,0 +1,110 @@ +source $DIRNAME/spacefish_test_setup.fish + +function setup + spacefish_test_setup + mock elixir -v 0 "echo \"Erlang/OTP 21 [erts-10.3.4] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe] [dtrace] +Elixir 1.8.1 (compiled with Erlang/OTP 21)\"" + set -x ELIXIR_VERSION 1.8.1 + mkdir -p /tmp/tmp-spacefish + cd /tmp/tmp-spacefish +end + +function teardown + rm -rf /tmp/tmp-spacefish +end + +test "Prints section when mix.exs is present" + ( + touch /tmp/tmp-spacefish/mix.exs + + set_color --bold + echo -n "via " + set_color normal + set_color --bold magenta + echo -n "馃挧 v1.8.1" + set_color normal + set_color --bold + echo -n " " + set_color normal + ) = (__sf_section_elixir) +end + +test "Prints section when a *.ex file is present" + ( + touch /tmp/tmp-spacefish/testfile.ex + + set_color --bold + echo -n "via " + set_color normal + set_color --bold magenta + echo -n "馃挧 v1.8.1" + set_color normal + set_color --bold + echo -n " " + set_color normal + ) = (__sf_section_elixir) +end + +test "Doesn't print the section when mix.exs and *.ex aren't present" + () = (__sf_section_elixir) +end + +test "Changing SPACEFISH_ELIXIR_SYMBOL changes the displayed character" + ( + touch /tmp/tmp-spacefish/mix.exs + set SPACEFISH_ELIXIR_SYMBOL "路 " + + set_color --bold + echo -n "via " + set_color normal + set_color --bold magenta + echo -n "路 v1.8.1" + set_color normal + set_color --bold + echo -n " " + set_color normal + ) = (__sf_section_elixir) +end + +test "Changing SPACEFISH_ELIXIR_PREFIX changes the character prefix" + ( + touch /tmp/tmp-spacefish/mix.exs + set sf_exit_code 0 + set SPACEFISH_ELIXIR_PREFIX 路 + + set_color --bold + echo -n "路" + set_color normal + set_color --bold magenta + echo -n "馃挧 v1.8.1" + set_color normal + set_color --bold + echo -n " " + set_color normal + ) = (__sf_section_elixir) +end + +test "Changing SPACEFISH_ELIXIR_SUFFIX changes the character suffix" + ( + touch /tmp/tmp-spacefish/mix.exs + set sf_exit_code 0 + set SPACEFISH_ELIXIR_SUFFIX 路 + + set_color --bold + echo -n "via " + set_color normal + set_color --bold magenta + echo -n "馃挧 v1.8.1" + set_color normal + set_color --bold + echo -n "路" + set_color normal + ) = (__sf_section_elixir) +end + +test "doesn't display the section when SPACEFISH_ELIXIR_SHOW is set to \"false\"" + ( + touch /tmp/tmp-spacefish/mix.exs + set SPACEFISH_ELIXIR_SHOW false + ) = (__sf_section_elixir) +end