Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(perl): Adding perl section (#1135)
* perl: Adding perl section to the project ** Added the perl section to grab perl version and set the project specific variables for perl. Perl is noted to be 5.x or previous where 6+ is no longer considered Perl. Added Docs for Perl. * docs(perl): Remove translations * docs(perl): Add docs to mkdocs * refactor(perl): Use section correctly * test(perl): Add tests for Perl * docs(perl): Update docs Co-authored-by: Denys Dovhan <denysdovhan@gmail.com>
- Loading branch information
1 parent
dd07d83
commit d3c2bf6
Showing
8 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Perl `perl` | ||
|
||
!!! important "This section is rendered asynchronously by default" | ||
|
||
!!! info | ||
[**Perl**](https://www.perl.org/) is a general purpose programming language, originally developed for text manipulation. | ||
|
||
The `perl` section displays the version of the Perl. | ||
|
||
This section is displayed only when the current directory is within a Perl project, meaning: | ||
|
||
* Upsearch finds a `META.json`, `META.yml`, `META.yaml`, `.perl-version`, or `cpanfile` file | ||
* Current directory contains any `.pl` or `.pm` file | ||
|
||
## Options | ||
|
||
| Variable | Default | Meaning | | ||
| :---------------------- | :--------------------------------: | ----------------------------------- | | ||
| `SPACESHIP_PERL_SHOW` | `true` | Show section | | ||
| `SPACESHIP_PERL_ASYNC` | `true` | Render section asynchronously | | ||
| `SPACESHIP_PERL_PREFIX` | `$SPACESHIP_PROMPT_DEFAULT_PREFIX` | Section's prefix | | ||
| `SPACESHIP_PERL_SUFFIX` | `$SPACESHIP_PROMPT_DEFAULT_SUFFIX` | Section's suffix | | ||
| `SPACESHIP_PERL_SYMBOL` | `🐪·` | Symbol displayed before the section | | ||
| `SPACESHIP_PERL_COLOR` | `blue` | Section's color | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# | ||
# Perl | ||
# | ||
# Perl is a general purpose programming language, originally developed for | ||
# text manipulation. | ||
# Perl refers to Perl 5.x, where Perl 6+ officially changed the name to Raku. | ||
# | ||
# Link: https://www.perl.org/ | ||
# ------------------------------------------------------------------------------ | ||
# Configuration | ||
# ------------------------------------------------------------------------------ | ||
|
||
SPACESHIP_PERL_SHOW="${SPACESHIP_PERL_SHOW=true}" | ||
SPACESHIP_PERL_ASYNC="${SPACESHIP_PHP_ASYNC=true}" | ||
SPACESHIP_PERL_PREFIX="${SPACESHIP_PERL_PREFIX="$SPACESHIP_PROMPT_DEFAULT_PREFIX"}" | ||
SPACESHIP_PERL_SUFFIX="${SPACESHIP_PERL_SUFFIX="$SPACESHIP_PROMPT_DEFAULT_SUFFIX"}" | ||
SPACESHIP_PERL_SYMBOL="${SPACESHIP_PERL_SYMBOL="🐪 "}" | ||
SPACESHIP_PERL_COLOR="${SPACESHIP_PERL_COLOR="blue"}" | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Section | ||
# ------------------------------------------------------------------------------ | ||
|
||
# Show current version of Perl | ||
spaceship_perl() { | ||
[[ $SPACESHIP_PERL_SHOW == false ]] && return | ||
|
||
spaceship::exists perl || return | ||
|
||
# Show only if perl files or composer.json exist in current directory | ||
local is_perl_project="$(spaceship::upsearch META.json META.yml META.yaml .perl-version cpanfile)" | ||
[[ -n "$is_perl_project" || -n *.pl(#qN^/) || -n *.pm(#qN^/) ]] || return | ||
|
||
local perl_version=$(perl -v 2>&1 | awk '/This/ {print $9}' | sed -r 's/[(v]+//g;s/[)]//g') | ||
|
||
spaceship::section \ | ||
--color "$SPACESHIP_PERL_COLOR" \ | ||
--prefix "$SPACESHIP_PERL_PREFIX" \ | ||
--suffix "$SPACESHIP_PERL_SUFFIX" \ | ||
--symbol "$SPACESHIP_PERL_SYMBOL" \ | ||
"v$perl_version" | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/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 | ||
|
||
PERL_VERSION="5.30.3" | ||
|
||
SPACESHIP_PROMPT_ASYNC=false | ||
SPACESHIP_PROMPT_FIRST_PREFIX_SHOW=true | ||
SPACESHIP_PROMPT_ADD_NEWLINE=false | ||
SPACESHIP_PROMPT_ORDER=(perl) | ||
|
||
source "spaceship.zsh" | ||
} | ||
|
||
setUp() { | ||
SPACESHIP_PERL_SHOW="true" | ||
SPACESHIP_PERL_PREFIX="via " | ||
SPACESHIP_PERL_SUFFIX="" | ||
SPACESHIP_PERL_SYMBOL="🐪 " | ||
SPACESHIP_PERL_COLOR="blue" | ||
|
||
cd $SHUNIT_TMPDIR | ||
} | ||
|
||
oneTimeTearDown() { | ||
unset SPACESHIP_PROMPT_FIRST_PREFIX_SHOW | ||
unset SPACESHIP_PROMPT_ADD_NEWLINE | ||
unset SPACESHIP_PROMPT_ORDER | ||
} | ||
|
||
tearDown() { | ||
unset SPACESHIP_PERL_SHOW | ||
unset SPACESHIP_PERL_PREFIX | ||
unset SPACESHIP_PERL_SUFFIX | ||
unset SPACESHIP_PERL_SYMBOL | ||
unset SPACESHIP_PERL_COLOR | ||
} | ||
|
||
# ------------------------------------------------------------------------------ | ||
# TEST CASES | ||
# ------------------------------------------------------------------------------ | ||
|
||
test_no_files() { | ||
local expected="" | ||
local actual="$(spaceship::testkit::render_prompt)" | ||
assertEquals "should not render without files" "$expected" "$actual" | ||
} | ||
|
||
test_dart_upsearch_file() { | ||
FILES=(META.json META.yml META.yaml .perl-version cpanfile) | ||
for file in $FILES; do | ||
touch $file | ||
local expected="%{%B%}$SPACESHIP_PERL_PREFIX%{%b%}%{%B%F{$SPACESHIP_PERL_COLOR}%}${SPACESHIP_PERL_SYMBOL}v$PERL_VERSION%{%b$SPACESHIP_PERL_SUFFIX%f%}" | ||
local actual="$(spaceship::testkit::render_prompt)" | ||
assertEquals "should render with $file" "$expected" "$actual" | ||
rm $file | ||
done | ||
} | ||
|
||
test_dart_file_extension() { | ||
FILES=(first.pl second.pm) | ||
for file in $FILES; do | ||
touch $file | ||
local expected="%{%B%}$SPACESHIP_PERL_PREFIX%{%b%}%{%B%F{$SPACESHIP_PERL_COLOR}%}${SPACESHIP_PERL_SYMBOL}v$PERL_VERSION%{%b$SPACESHIP_PERL_SUFFIX%f%}" | ||
local actual="$(spaceship::testkit::render_prompt)" | ||
assertEquals "should render with $file" "$expected" "$actual" | ||
rm $file | ||
done | ||
} | ||
|
||
# ------------------------------------------------------------------------------ | ||
# SHUNIT2 | ||
# Run tests with shunit2 | ||
# ------------------------------------------------------------------------------ | ||
|
||
source tests/shunit2/shunit2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env zsh | ||
|
||
printf 'This is perl 5, version 30, subversion 3 (v5.30.3) built for darwin-thread-multi-2level\n' |