Thanks to visit codestin.com
Credit goes to github.com

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

Commit 3d777fc

Browse files
newmaniesematchai
authored andcommitted
feat: add Python venv section (#164)
This PR adds the requested features to #146 Tests and docs updated as well
1 parent 5006c93 commit 3d777fc

File tree

5 files changed

+115
-14
lines changed

5 files changed

+115
-14
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ Spacefish is a minimalistic, powerful and extremely customizable <a href="https:
7777
* Current Rust version (`𝗥`).
7878
* Current version of Haskell GHC Compiler, defined in stack.yaml file (`λ`).
7979
* Current Julia version (``).
80-
* Current Conda version (`🅒`).
8180
* Current Amazon Web Services (AWS) profile (`☁️`) ([Using named profiles](http://docs.aws.amazon.com/cli/latest/userguide/cli-multiple-profiles.html)).
81+
* Current Python virtualenv.
82+
* Current Conda version (`🅒`).
8283
* Current Python pyenv (`🐍`).
8384
* Current .NET SDK version, through dotnet-cli (`.NET`).
8485
* Current Kubectl context (`☸️`).

docs/Options.md

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -218,18 +218,6 @@ Haskell section is shown only in directories that contain `stack.yaml`.
218218
| `SPACEFISH_HASKELL_SYMBOL` | `λ·` | Character to be shown before Haskell version |
219219
| `SPACEFISH_HASKELL_COLOR` | `red` | Color of Haskell section |
220220

221-
### Conda \(`conda`\)
222-
223-
Conda section is shown when ```conda``` is installed and $CONDA_DEFAULT_ENV is set.
224-
225-
| Variable | Default | Meaning |
226-
| :------- | :-----: | ------- |
227-
| `SPACEFISH_CONDA_SHOW` | `true` | Show current Conda version |
228-
| `SPACEFISH_CONDA_PREFIX` | `$SPACEFISH_PROMPT_DEFAULT_PREFIX` | Prefix before the conda section |
229-
| `SPACEFISH_CONDA_SUFFIX` | `$SPACEFISH_PROMPT_DEFAULT_SUFFIX` | Suffix after the conda section |
230-
| `SPACEFISH_CONDA_SYMBOL` | `🅒·` | Character to be shown before Conda version |
231-
| `SPACEFISH_CONDA_COLOR` | `blue` | Color of Conda section |
232-
233221
### Amazon Web Services (AWS) (`aws`)
234222

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

233+
### Virtualenv (`venv`)
234+
235+
Python virtual environment when $VIRTUAL_ENV is set.
236+
237+
| Variable | Default | Meaning |
238+
| :------- | :-----: | ------- |
239+
| `SPACEFISH_VENV_SHOW` | `true` | Show current Python virtualenv or not |
240+
| `SPACEFISH_VENV_PREFIX` | `$SPACEFISH_PROMPT_DEFAULT_PREFIX` | Prefix before the virtualenv section |
241+
| `SPACEFISH_VENV_SUFFIX` | `$SPACEFISH_PROMPT_DEFAULT_SUFFIX` | Suffix after the virtualenv section |
242+
| `SPACEFISH_VENV_SYMBOL` | `·` | Character to be shown before virtualenv |
243+
| `SPACEFISH_VENV_GENERIC_NAMES` | `virtualenv venv .venv` | If the virtualenv folder is in this *array*, than use its parent directory as its name instead |
244+
| `SPACEFISH_VENV_COLOR` | `blue` | Color of virtualenv environment section |
245+
246+
247+
### Conda \(`conda`\)
248+
249+
Conda section is shown when ```conda``` is installed and $CONDA_DEFAULT_ENV is set.
250+
251+
| Variable | Default | Meaning |
252+
| :------- | :-----: | ------- |
253+
| `SPACEFISH_CONDA_SHOW` | `true` | Show current Conda version |
254+
| `SPACEFISH_CONDA_PREFIX` | `$SPACEFISH_PROMPT_DEFAULT_PREFIX` | Prefix before the conda section |
255+
| `SPACEFISH_CONDA_SUFFIX` | `$SPACEFISH_PROMPT_DEFAULT_SUFFIX` | Suffix after the conda section |
256+
| `SPACEFISH_CONDA_SYMBOL` | `🅒·` | Character to be shown before Conda version |
257+
| `SPACEFISH_CONDA_COLOR` | `blue` | Color of Conda section |
258+
245259
### Pyenv \(`pyenv`\)
246260

247261
Pyenv section is shown only in directories that contain `.python-version`, `requirements.txt`, `pyproject.toml`, or any other file with `.py` extension.

fish_prompt.fish

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function fish_prompt
1313
__sf_util_set_default SPACEFISH_PROMPT_SUFFIXES_SHOW true
1414
__sf_util_set_default SPACEFISH_PROMPT_DEFAULT_PREFIX "via "
1515
__sf_util_set_default SPACEFISH_PROMPT_DEFAULT_SUFFIX " "
16-
__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
16+
__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
1717

1818
# ------------------------------------------------------------------------------
1919
# Sections

functions/__sf_section_venv.fish

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# virtualenv
2+
#
3+
4+
function __sf_section_venv -d "Show current virtual Python environment"
5+
# ------------------------------------------------------------------------------
6+
# Configuration
7+
# ------------------------------------------------------------------------------
8+
9+
__sf_util_set_default SPACEFISH_VENV_SHOW true
10+
__sf_util_set_default SPACEFISH_VENV_PREFIX $SPACEFISH_PROMPT_DEFAULT_PREFIX
11+
__sf_util_set_default SPACEFISH_VENV_SUFFIX $SPACEFISH_PROMPT_DEFAULT_SUFFIX
12+
__sf_util_set_default SPACEFISH_VENV_SYMBOL "·"
13+
__sf_util_set_default SPACESHIP_VENV_GENERIC_NAMES virtualenv venv .venv
14+
__sf_util_set_default SPACEFISH_VENV_COLOR blue
15+
16+
# ------------------------------------------------------------------------------
17+
# Section
18+
# ------------------------------------------------------------------------------
19+
20+
# Show venv python version
21+
test $SPACEFISH_VENV_SHOW = false; and return
22+
23+
# Check if the current directory running via Virtualenv
24+
test -n "$VIRTUAL_ENV"; or return
25+
26+
set -l venv (basename $VIRTUAL_ENV)
27+
if contains $venv $SPACESHIP_VENV_GENERIC_NAMES
28+
set venv (basename (dirname $VIRTUAL_ENV))
29+
end
30+
31+
__sf_lib_section \
32+
$SPACEFISH_VENV_COLOR \
33+
$SPACEFISH_VENV_PREFIX \
34+
"$SPACEFISH_VENV_SYMBOL""$venv" \
35+
$SPACEFISH_VENV_SUFFIX
36+
end

tests/__sf_section_venv.test.fish

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
source $DIRNAME/spacefish_test_setup.fish
2+
3+
function setup
4+
spacefish_test_setup
5+
end
6+
7+
function teardown
8+
if test "$VIRTUAL_ENV"
9+
set -e VIRTUAL_ENV
10+
end
11+
end
12+
13+
test "Prints section when \$VIRTUAL_ENV is defined"
14+
(
15+
set VIRTUAL_ENV "/Users/JaneDoe/.venv/coolenviron"
16+
17+
set_color --bold
18+
echo -n $SPACEFISH_PROMPT_DEFAULT_PREFIX
19+
set_color normal
20+
set_color --bold blue
21+
echo -n "·coolenviron"
22+
set_color normal
23+
set_color --bold
24+
echo -n $SPACEFISH_PROMPT_DEFAULT_SUFFIX
25+
set_color normal
26+
) = (__sf_section_venv)
27+
end
28+
29+
test "Prints section when \$VIRTUAL_ENV is defined with venv as the directory name"
30+
(
31+
set VIRTUAL_ENV "/Users/JaneDoe/.venv/coolenviron/virtualenv"
32+
33+
set_color --bold
34+
echo -n $SPACEFISH_PROMPT_DEFAULT_PREFIX
35+
set_color normal
36+
set_color --bold blue
37+
echo -n "·coolenviron"
38+
set_color normal
39+
set_color --bold
40+
echo -n $SPACEFISH_PROMPT_DEFAULT_SUFFIX
41+
set_color normal
42+
) = (__sf_section_venv)
43+
end
44+
45+
test "doesn't display the section when SPACEFISH_VENV_SHOW is set to \"false\""
46+
(
47+
set VIRTUAL_ENV "/Users/JaneDoe/.venv/coolenviron"
48+
set SPACEFISH_VENV_SHOW false
49+
) = (__sf_section_venv)
50+
end

0 commit comments

Comments
 (0)