summaryrefslogtreecommitdiff
path: root/fish/.config/fish/functions/_tide_item_python.fish
diff options
context:
space:
mode:
Diffstat (limited to 'fish/.config/fish/functions/_tide_item_python.fish')
-rw-r--r--fish/.config/fish/functions/_tide_item_python.fish27
1 files changed, 27 insertions, 0 deletions
diff --git a/fish/.config/fish/functions/_tide_item_python.fish b/fish/.config/fish/functions/_tide_item_python.fish
new file mode 100644
index 0000000..57f7075
--- /dev/null
+++ b/fish/.config/fish/functions/_tide_item_python.fish
@@ -0,0 +1,27 @@
+function _tide_item_python
+ if test -n "$VIRTUAL_ENV"
+ if command -q python3
+ python3 --version | string match -qr "(?<v>[\d.]+)"
+ else
+ python --version | string match -qr "(?<v>[\d.]+)"
+ end
+ string match -qr "^.*/(?<dir>.*)/(?<base>.*)" $VIRTUAL_ENV
+ # pipenv $VIRTUAL_ENV looks like /home/ilan/.local/share/virtualenvs/pipenv_project-EwRYuc3l
+ # Detect whether we are using pipenv by looking for 'virtualenvs'. If so, remove the hash at the end.
+ if test "$dir" = virtualenvs
+ string match -qr "(?<base>.*)-.*" $base
+ _tide_print_item python $tide_python_icon' ' "$v ($base)"
+ else if contains -- "$base" virtualenv venv .venv env # avoid generic names
+ _tide_print_item python $tide_python_icon' ' "$v ($dir)"
+ else
+ _tide_print_item python $tide_python_icon' ' "$v ($base)"
+ end
+ else if path is .python-version Pipfile __init__.py pyproject.toml requirements.txt setup.py
+ if command -q python3
+ python3 --version | string match -qr "(?<v>[\d.]+)"
+ else
+ python --version | string match -qr "(?<v>[\d.]+)"
+ end
+ _tide_print_item python $tide_python_icon' ' $v
+ end
+end