home-config/fish/functions/_tide_item_python.fish

c5bc1749c7a31d17fb5a3a122674e078086bb7d2 · 1.2 KB · 27 lines raw

1 function _tide_item_python
2 if test -n "$VIRTUAL_ENV"
3 if command -q python3
4 python3 --version | string match -qr "(?<v>[\d.]+)"
5 else
6 python --version | string match -qr "(?<v>[\d.]+)"
7 end
8 string match -qr "^.*/(?<dir>.*)/(?<base>.*)" $VIRTUAL_ENV
9 # pipenv $VIRTUAL_ENV looks like /home/ilan/.local/share/virtualenvs/pipenv_project-EwRYuc3l
10 # Detect whether we are using pipenv by looking for 'virtualenvs'. If so, remove the hash at the end.
11 if test "$dir" = virtualenvs
12 string match -qr "(?<base>.*)-.*" $base
13 _tide_print_item python $tide_python_icon' ' "$v ($base)"
14 else if contains -- "$base" virtualenv venv .venv env # avoid generic names
15 _tide_print_item python $tide_python_icon' ' "$v ($dir)"
16 else
17 _tide_print_item python $tide_python_icon' ' "$v ($base)"
18 end
19 else if path is .python-version Pipfile __init__.py pyproject.toml requirements.txt setup.py
20 if command -q python3
21 python3 --version | string match -qr "(?<v>[\d.]+)"
22 else
23 python --version | string match -qr "(?<v>[\d.]+)"
24 end
25 _tide_print_item python $tide_python_icon' ' $v
26 end
27 end