Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
feat: Add elixir section (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
bradcypert authored and matchai committed Jun 19, 2019
1 parent 1fd54ea commit 9cb48ea
Show file tree
Hide file tree
Showing 8 changed files with 216 additions and 11 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Spacefish is a minimalistic, powerful and extremely customizable <a href="https:
* Current Amazon Web Services (AWS) profile (`☁️`) ([Using named profiles](http://docs.aws.amazon.com/cli/latest/userguide/cli-multiple-profiles.html)).
* Current Python virtualenv.
* Current Conda version (`🅒`).
* Current Elixir Version (`💧`).
* Current Python pyenv (`🐍`).
* Current .NET SDK version, through dotnet-cli (`.NET`).
* Current Kubectl context (`☸️`).
Expand Down Expand Up @@ -139,7 +140,7 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds
| [<img src="https://avatars0.githubusercontent.com/u/4658208?v=4" width="100px;"/><br /><sub><b>Matan Kushner</b></sub>](https://twitter.com/matchai)<br />[🐛](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") | [<img src="https://avatars2.githubusercontent.com/u/11183523?v=4" width="100px;"/><br /><sub><b>Tiffany Le-Nguyen</b></sub>](https://github.com/sirMerr)<br />[🐛](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") | [<img src="https://avatars0.githubusercontent.com/u/26250962?v=4" width="100px;"/><br /><sub><b>Snuggle</b></sub>](https://github.com/Snuggle)<br />[🐛](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") | [<img src="https://avatars2.githubusercontent.com/u/11844760?v=4" width="100px;"/><br /><sub><b>Jaskaran Bindra</b></sub>](https://github.com/jskrnbindra)<br />[💻](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") | [<img src="https://avatars3.githubusercontent.com/u/6306918?v=4" width="100px;"/><br /><sub><b>Konstantin Labun</b></sub>](https://labun.me)<br />[💻](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") | [<img src="https://avatars0.githubusercontent.com/u/2652762?v=4" width="100px;"/><br /><sub><b>Kyle Holzinger</b></sub>](https://medium.com/@kyleholzinger)<br />[💻](https://github.com/matchai/spacefish/commits?author=kyleholzinger "Code") [📖](https://github.com/matchai/spacefish/commits?author=kyleholzinger "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/10276208?v=4" width="100px;"/><br /><sub><b>Salmanul Farzy</b></sub>](https://github.com/salmanulfarzy)<br />[💻](https://github.com/matchai/spacefish/commits?author=salmanulfarzy "Code") [👀](#review-salmanulfarzy "Reviewed Pull Requests") |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| [<img src="https://avatars0.githubusercontent.com/u/46186?v=4" width="100px;"/><br /><sub><b>owais</b></sub>](https://owais.lone.pw)<br />[💻](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") | [<img src="https://avatars3.githubusercontent.com/u/35412203?v=4" width="100px;"/><br /><sub><b>Samantha Enders</b></sub>](https://github.com/ladysamantha)<br />[💻](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") | [<img src="https://avatars2.githubusercontent.com/u/887196?v=4" width="100px;"/><br /><sub><b>Evan Relf</b></sub>](https://evanrelf.com)<br />[💻](https://github.com/matchai/spacefish/commits?author=evanrelf "Code") [📖](https://github.com/matchai/spacefish/commits?author=evanrelf "Documentation") | [<img src="https://avatars1.githubusercontent.com/u/10660468?v=4" width="100px;"/><br /><sub><b>Jason Etcovitch</b></sub>](https://jasonet.co)<br />[💻](https://github.com/matchai/spacefish/commits?author=JasonEtco "Code") [📖](https://github.com/matchai/spacefish/commits?author=JasonEtco "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/4988133?v=4" width="100px;"/><br /><sub><b>hrvoj3e</b></sub>](https://github.com/hrvoj3e)<br />[🐛](https://github.com/matchai/spacefish/issues?q=author%3Ahrvoj3e "Bug reports") [💻](https://github.com/matchai/spacefish/commits?author=hrvoj3e "Code") | [<img src="https://avatars1.githubusercontent.com/u/64894?v=4" width="100px;"/><br /><sub><b>Michael Newman</b></sub>](http://newmaniese.com)<br />[🐛](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") | [<img src="https://avatars0.githubusercontent.com/u/6491400?v=4" width="100px;"/><br /><sub><b>Konrad</b></sub>](https://github.com/k-lyda)<br />[🐛](https://github.com/matchai/spacefish/issues?q=author%3Ak-lyda "Bug reports") |
| [<img src="https://avatars1.githubusercontent.com/u/3227558?v=4" width="100px;"/><br /><sub><b>Will Neville</b></sub>](https://github.com/dubnev)<br />[🐛](https://github.com/matchai/spacefish/issues?q=author%3Adubnev "Bug reports") | [<img src="https://avatars1.githubusercontent.com/u/4022138?v=4" width="100px;"/><br /><sub><b>Daniel Trautmann</b></sub>](https://github.com/danieltrautmann)<br />[💻](https://github.com/matchai/spacefish/commits?author=danieltrautmann "Code") | [<img src="https://avatars0.githubusercontent.com/u/16061385?v=4" width="100px;"/><br /><sub><b>Jonas Öhlander</b></sub>](https://github.com/Menturan)<br />[🐛](https://github.com/matchai/spacefish/issues?q=author%3AMenturan "Bug reports") | [<img src="https://avatars1.githubusercontent.com/u/3099491?v=4" width="100px;"/><br /><sub><b>lindsay</b></sub>](https://twitter.com/lynzt)<br />[📖](https://github.com/matchai/spacefish/commits?author=lynzt "Documentation") | [<img src="https://avatars3.githubusercontent.com/u/23652004?v=4" width="100px;"/><br /><sub><b>Nam Nguyen</b></sub>](https://github.com/nammn)<br />[💻](https://github.com/matchai/spacefish/commits?author=nammn "Code") |
| [<img src="https://avatars1.githubusercontent.com/u/3227558?v=4" width="100px;"/><br /><sub><b>Will Neville</b></sub>](https://github.com/dubnev)<br />[🐛](https://github.com/matchai/spacefish/issues?q=author%3Adubnev "Bug reports") | [<img src="https://avatars1.githubusercontent.com/u/4022138?v=4" width="100px;"/><br /><sub><b>Daniel Trautmann</b></sub>](https://github.com/danieltrautmann)<br />[💻](https://github.com/matchai/spacefish/commits?author=danieltrautmann "Code") | [<img src="https://avatars0.githubusercontent.com/u/16061385?v=4" width="100px;"/><br /><sub><b>Jonas Öhlander</b></sub>](https://github.com/Menturan)<br />[🐛](https://github.com/matchai/spacefish/issues?q=author%3AMenturan "Bug reports") | [<img src="https://avatars1.githubusercontent.com/u/3099491?v=4" width="100px;"/><br /><sub><b>lindsay</b></sub>](https://twitter.com/lynzt)<br />[📖](https://github.com/matchai/spacefish/commits?author=lynzt "Documentation") | [<img src="https://avatars3.githubusercontent.com/u/23652004?v=4" width="100px;"/><br /><sub><b>Nam Nguyen</b></sub>](https://github.com/nammn)<br />[💻](https://github.com/matchai/spacefish/commits?author=nammn "Code") | [<img src="https://avatars0.githubusercontent.com/u/1455979?v=4" width="100px;"/><br /><sub><b>Brad</b></sub>](http://www.bradcypert.com)<br />[💻](https://github.com/matchai/spacefish/commits?author=bradcypert "Code") |
<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!
Expand Down
13 changes: 13 additions & 0 deletions docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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 @@
* [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)
Expand Down
2 changes: 1 addition & 1 deletion fish_prompt.fish
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 57 additions & 0 deletions functions/__sf_section_elixir.fish
Original file line number Diff line number Diff line change
@@ -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
32 changes: 23 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
]
]
}
}
110 changes: 110 additions & 0 deletions tests/__sf_section_elixir.test.fish
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9cb48ea

Please sign in to comment.