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

Commit

Permalink
feat: add Python venv section (#164)
Browse files Browse the repository at this point in the history
This PR adds the requested features to #146
Tests and docs updated as well
  • Loading branch information
newmaniese authored and matchai committed Feb 24, 2019
1 parent 5006c93 commit 3d777fc
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 14 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ Spacefish is a minimalistic, powerful and extremely customizable <a href="https:
* Current Rust version (`𝗥`).
* Current version of Haskell GHC Compiler, defined in stack.yaml file (`λ`).
* Current Julia version (``).
* Current Conda version (`🅒`).
* 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 Python pyenv (`🐍`).
* Current .NET SDK version, through dotnet-cli (`.NET`).
* Current Kubectl context (`☸️`).
Expand Down
38 changes: 26 additions & 12 deletions docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,18 +218,6 @@ Haskell section is shown only in directories that contain `stack.yaml`.
| `SPACEFISH_HASKELL_SYMBOL` | `λ·` | Character to be shown before Haskell version |
| `SPACEFISH_HASKELL_COLOR` | `red` | Color of Haskell section |

### Conda \(`conda`\)

Conda section is shown when ```conda``` is installed and $CONDA_DEFAULT_ENV is set.

| Variable | Default | Meaning |
| :------- | :-----: | ------- |
| `SPACEFISH_CONDA_SHOW` | `true` | Show current Conda version |
| `SPACEFISH_CONDA_PREFIX` | `$SPACEFISH_PROMPT_DEFAULT_PREFIX` | Prefix before the conda section |
| `SPACEFISH_CONDA_SUFFIX` | `$SPACEFISH_PROMPT_DEFAULT_SUFFIX` | Suffix after the conda section |
| `SPACEFISH_CONDA_SYMBOL` | `🅒·` | Character to be shown before Conda version |
| `SPACEFISH_CONDA_COLOR` | `blue` | Color of Conda section |

### Amazon Web Services (AWS) (`aws`)

Shows selected Amazon Web Services profile configured using [`AWS_PROFILE`](http://docs.aws.amazon.com/cli/latest/userguide/cli-multiple-profiles.html) variable.
Expand All @@ -242,6 +230,32 @@ Shows selected Amazon Web Services profile configured using [`AWS_PROFILE`](htt
| `SPACESHIP_AWS_SYMBOL` | `☁️·` | Character to be shown before AWS profile |
| `SPACESHIP_AWS_COLOR` | `ff8700` | Color of AWS section |

### Virtualenv (`venv`)

Python virtual environment when $VIRTUAL_ENV is set.

| Variable | Default | Meaning |
| :------- | :-----: | ------- |
| `SPACEFISH_VENV_SHOW` | `true` | Show current Python virtualenv or not |
| `SPACEFISH_VENV_PREFIX` | `$SPACEFISH_PROMPT_DEFAULT_PREFIX` | Prefix before the virtualenv section |
| `SPACEFISH_VENV_SUFFIX` | `$SPACEFISH_PROMPT_DEFAULT_SUFFIX` | Suffix after the virtualenv section |
| `SPACEFISH_VENV_SYMBOL` | `·` | Character to be shown before virtualenv |
| `SPACEFISH_VENV_GENERIC_NAMES` | `virtualenv venv .venv` | If the virtualenv folder is in this *array*, than use its parent directory as its name instead |
| `SPACEFISH_VENV_COLOR` | `blue` | Color of virtualenv environment section |


### Conda \(`conda`\)

Conda section is shown when ```conda``` is installed and $CONDA_DEFAULT_ENV is set.

| Variable | Default | Meaning |
| :------- | :-----: | ------- |
| `SPACEFISH_CONDA_SHOW` | `true` | Show current Conda version |
| `SPACEFISH_CONDA_PREFIX` | `$SPACEFISH_PROMPT_DEFAULT_PREFIX` | Prefix before the conda section |
| `SPACEFISH_CONDA_SUFFIX` | `$SPACEFISH_PROMPT_DEFAULT_SUFFIX` | Suffix after the conda section |
| `SPACEFISH_CONDA_SYMBOL` | `🅒·` | Character to be shown before Conda version |
| `SPACEFISH_CONDA_COLOR` | `blue` | Color of Conda 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
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 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 docker aws venv conda pyenv dotnet kubecontext exec_time line_sep battery vi_mode jobs exit_code char

# ------------------------------------------------------------------------------
# Sections
Expand Down
36 changes: 36 additions & 0 deletions functions/__sf_section_venv.fish
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
50 changes: 50 additions & 0 deletions tests/__sf_section_venv.test.fish
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

0 comments on commit 3d777fc

Please sign in to comment.