This repository has been archived by the owner on Feb 3, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Python venv section (#164)
This PR adds the requested features to #146 Tests and docs updated as well
- Loading branch information
1 parent
5006c93
commit 3d777fc
Showing
5 changed files
with
115 additions
and
14 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
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,36 @@ | ||
# virtualenv | ||
# | ||
|
||
function __sf_section_venv -d "Show current virtual Python environment" | ||
# ------------------------------------------------------------------------------ | ||
# Configuration | ||
# ------------------------------------------------------------------------------ | ||
|
||
__sf_util_set_default SPACEFISH_VENV_SHOW true | ||
__sf_util_set_default SPACEFISH_VENV_PREFIX $SPACEFISH_PROMPT_DEFAULT_PREFIX | ||
__sf_util_set_default SPACEFISH_VENV_SUFFIX $SPACEFISH_PROMPT_DEFAULT_SUFFIX | ||
__sf_util_set_default SPACEFISH_VENV_SYMBOL "·" | ||
__sf_util_set_default SPACESHIP_VENV_GENERIC_NAMES virtualenv venv .venv | ||
__sf_util_set_default SPACEFISH_VENV_COLOR blue | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Section | ||
# ------------------------------------------------------------------------------ | ||
|
||
# Show venv python version | ||
test $SPACEFISH_VENV_SHOW = false; and return | ||
|
||
# Check if the current directory running via Virtualenv | ||
test -n "$VIRTUAL_ENV"; or return | ||
|
||
set -l venv (basename $VIRTUAL_ENV) | ||
if contains $venv $SPACESHIP_VENV_GENERIC_NAMES | ||
set venv (basename (dirname $VIRTUAL_ENV)) | ||
end | ||
|
||
__sf_lib_section \ | ||
$SPACEFISH_VENV_COLOR \ | ||
$SPACEFISH_VENV_PREFIX \ | ||
"$SPACEFISH_VENV_SYMBOL""$venv" \ | ||
$SPACEFISH_VENV_SUFFIX | ||
end |
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,50 @@ | ||
source $DIRNAME/spacefish_test_setup.fish | ||
|
||
function setup | ||
spacefish_test_setup | ||
end | ||
|
||
function teardown | ||
if test "$VIRTUAL_ENV" | ||
set -e VIRTUAL_ENV | ||
end | ||
end | ||
|
||
test "Prints section when \$VIRTUAL_ENV is defined" | ||
( | ||
set VIRTUAL_ENV "/Users/JaneDoe/.venv/coolenviron" | ||
|
||
set_color --bold | ||
echo -n $SPACEFISH_PROMPT_DEFAULT_PREFIX | ||
set_color normal | ||
set_color --bold blue | ||
echo -n "·coolenviron" | ||
set_color normal | ||
set_color --bold | ||
echo -n $SPACEFISH_PROMPT_DEFAULT_SUFFIX | ||
set_color normal | ||
) = (__sf_section_venv) | ||
end | ||
|
||
test "Prints section when \$VIRTUAL_ENV is defined with venv as the directory name" | ||
( | ||
set VIRTUAL_ENV "/Users/JaneDoe/.venv/coolenviron/virtualenv" | ||
|
||
set_color --bold | ||
echo -n $SPACEFISH_PROMPT_DEFAULT_PREFIX | ||
set_color normal | ||
set_color --bold blue | ||
echo -n "·coolenviron" | ||
set_color normal | ||
set_color --bold | ||
echo -n $SPACEFISH_PROMPT_DEFAULT_SUFFIX | ||
set_color normal | ||
) = (__sf_section_venv) | ||
end | ||
|
||
test "doesn't display the section when SPACEFISH_VENV_SHOW is set to \"false\"" | ||
( | ||
set VIRTUAL_ENV "/Users/JaneDoe/.venv/coolenviron" | ||
set SPACEFISH_VENV_SHOW false | ||
) = (__sf_section_venv) | ||
end |