Skip to content

Commit

Permalink
Replace virtual_env item with more general python item
Browse files Browse the repository at this point in the history
  • Loading branch information
IlanCosman committed Sep 24, 2023
1 parent 115a45f commit 10a1fab
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 50 deletions.
20 changes: 20 additions & 0 deletions functions/_tide_item_python.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function _tide_item_python
if test -n "$VIRTUAL_ENV"
python --version | string match -qr "(?<v>[\d.]+)"

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
python --version | string match -qr "(?<v>[\d.]+)"
_tide_print_item python $tide_python_icon' ' $v
end
end
11 changes: 0 additions & 11 deletions functions/_tide_item_virtual_env.fish

This file was deleted.

6 changes: 3 additions & 3 deletions functions/_tide_remove_unusable_items.fish
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
function _tide_remove_unusable_items
# Remove tool-specific items for tools the machine doesn't have installed
set -l removed_items
for item in aws crystal direnv distrobox docker elixir gcloud git go java kubectl nix_shell node php pulumi ruby rustc terraform toolbox virtual_env
for item in aws crystal direnv distrobox docker elixir gcloud git go java kubectl nix_shell node php pulumi python ruby rustc terraform toolbox
contains $item $tide_left_prompt_items $tide_right_prompt_items || continue

set -l cli_names $item
switch $item
case distrobox # there is no 'distrobox' command inside the container
set cli_names distrobox-export # 'distrobox-export' and 'distrobox-host-exec' are available
case virtual_env
set cli_names python python3
case nix_shell
set cli_names nix nix-shell
case python
set cli_names python python3
end
type --query $cli_names || set -a removed_items $item
end
Expand Down
6 changes: 3 additions & 3 deletions functions/tide/configure/configs/classic.fish
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ tide_pwd_color_anchors $_tide_color_light_blue
tide_pwd_color_dirs $_tide_color_dark_blue
tide_pwd_color_truncated_dirs 8787AF
tide_pwd_markers .bzr .citc .git .hg .node-version .python-version .ruby-version .shorten_folder_marker .svn .terraform Cargo.toml composer.json CVS go.mod package.json
tide_python_bg_color 444444
tide_python_color 00AFAF
tide_right_prompt_frame_enabled true
tide_right_prompt_items status cmd_duration context jobs direnv node virtual_env rustc java php pulumi ruby go gcloud kubectl distrobox toolbox terraform aws nix_shell crystal elixir
tide_right_prompt_items status cmd_duration context jobs direnv node python rustc java php pulumi ruby go gcloud kubectl distrobox toolbox terraform aws nix_shell crystal elixir
tide_right_prompt_prefix 
tide_right_prompt_separator_diff_color 
tide_right_prompt_separator_same_color 
Expand Down Expand Up @@ -109,5 +111,3 @@ tide_vi_mode_color_default 949494
tide_vi_mode_color_insert 87AFAF
tide_vi_mode_color_replace 87AF87
tide_vi_mode_color_visual FF8700
tide_virtual_env_bg_color 444444
tide_virtual_env_color 00AFAF
4 changes: 2 additions & 2 deletions functions/tide/configure/configs/classic_16color.fish
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ tide_pwd_bg_color black
tide_pwd_color_anchors brcyan
tide_pwd_color_dirs cyan
tide_pwd_color_truncated_dirs magenta
tide_python_bg_color black
tide_python_color cyan
tide_ruby_bg_color black
tide_ruby_color red
tide_rustc_bg_color black
Expand All @@ -83,5 +85,3 @@ tide_vi_mode_color_default white
tide_vi_mode_color_insert cyan
tide_vi_mode_color_replace green
tide_vi_mode_color_visual yellow
tide_virtual_env_bg_color black
tide_virtual_env_color cyan
6 changes: 3 additions & 3 deletions functions/tide/configure/configs/lean.fish
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ tide_pwd_color_anchors $_tide_color_light_blue
tide_pwd_color_dirs $_tide_color_dark_blue
tide_pwd_color_truncated_dirs 8787AF
tide_pwd_markers .bzr .citc .git .hg .node-version .python-version .ruby-version .shorten_folder_marker .svn .terraform Cargo.toml composer.json CVS go.mod package.json
tide_python_bg_color normal
tide_python_color 00AFAF
tide_right_prompt_frame_enabled false
tide_right_prompt_items status cmd_duration context jobs direnv node virtual_env rustc java php pulumi ruby go gcloud kubectl distrobox toolbox terraform aws nix_shell crystal elixir
tide_right_prompt_items status cmd_duration context jobs direnv node python rustc java php pulumi ruby go gcloud kubectl distrobox toolbox terraform aws nix_shell crystal elixir
tide_right_prompt_prefix ' '
tide_right_prompt_separator_diff_color ' '
tide_right_prompt_separator_same_color ' '
Expand Down Expand Up @@ -109,5 +111,3 @@ tide_vi_mode_color_default 949494
tide_vi_mode_color_insert 87AFAF
tide_vi_mode_color_replace 87AF87
tide_vi_mode_color_visual FF8700
tide_virtual_env_bg_color normal
tide_virtual_env_color 00AFAF
4 changes: 2 additions & 2 deletions functions/tide/configure/configs/lean_16color.fish
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ tide_pwd_bg_color normal
tide_pwd_color_anchors brcyan
tide_pwd_color_dirs cyan
tide_pwd_color_truncated_dirs magenta
tide_python_bg_color normal
tide_python_color cyan
tide_ruby_bg_color normal
tide_ruby_color red
tide_rustc_bg_color normal
Expand All @@ -83,5 +85,3 @@ tide_vi_mode_color_default white
tide_vi_mode_color_insert cyan
tide_vi_mode_color_replace green
tide_vi_mode_color_visual yellow
tide_virtual_env_bg_color normal
tide_virtual_env_color cyan
6 changes: 3 additions & 3 deletions functions/tide/configure/configs/rainbow.fish
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ tide_pwd_color_anchors E4E4E4
tide_pwd_color_dirs E4E4E4
tide_pwd_color_truncated_dirs BCBCBC
tide_pwd_markers .bzr .citc .git .hg .node-version .python-version .ruby-version .shorten_folder_marker .svn .terraform Cargo.toml composer.json CVS go.mod package.json
tide_python_bg_color 444444
tide_python_color 00AFAF
tide_right_prompt_frame_enabled true
tide_right_prompt_items status cmd_duration context jobs direnv node virtual_env rustc java php pulumi ruby go gcloud kubectl distrobox toolbox terraform aws nix_shell crystal elixir
tide_right_prompt_items status cmd_duration context jobs direnv node python rustc java php pulumi ruby go gcloud kubectl distrobox toolbox terraform aws nix_shell crystal elixir
tide_right_prompt_prefix 
tide_right_prompt_separator_diff_color 
tide_right_prompt_separator_same_color 
Expand Down Expand Up @@ -109,5 +111,3 @@ tide_vi_mode_color_default 000000
tide_vi_mode_color_insert 000000
tide_vi_mode_color_replace 000000
tide_vi_mode_color_visual 000000
tide_virtual_env_bg_color 444444
tide_virtual_env_color 00AFAF
4 changes: 2 additions & 2 deletions functions/tide/configure/configs/rainbow_16color.fish
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ tide_pwd_bg_color blue
tide_pwd_color_anchors brwhite
tide_pwd_color_dirs brwhite
tide_pwd_color_truncated_dirs white
tide_python_bg_color brblack
tide_python_color cyan
tide_ruby_bg_color red
tide_ruby_color black
tide_rustc_bg_color red
Expand Down Expand Up @@ -87,5 +89,3 @@ tide_vi_mode_icon_default D
tide_vi_mode_icon_insert I
tide_vi_mode_icon_replace R
tide_vi_mode_icon_visual V
tide_virtual_env_bg_color brblack
tide_virtual_env_color cyan
2 changes: 1 addition & 1 deletion functions/tide/configure/icons.fish
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ tide_pulumi_icon 
tide_pwd_icon
tide_pwd_icon_home
tide_pwd_icon_unwritable 
tide_python_icon 󰌠
tide_ruby_icon 
tide_rustc_icon 
tide_shlvl_icon 
Expand All @@ -36,4 +37,3 @@ tide_vi_mode_icon_default D
tide_vi_mode_icon_insert I
tide_vi_mode_icon_replace R
tide_vi_mode_icon_visual V
tide_virtual_env_icon 󰌠
28 changes: 28 additions & 0 deletions tests/_tide_item_python.test.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# RUN: %fish %s
_tide_parent_dirs

function _python
_tide_decolor (_tide_item_python)
end

set -lx tide_python_icon 
mock python --version "echo 'Python 3.11.5'"

set -lx VIRTUAL_ENV
_python # CHECK:

set -lx VIRTUAL_ENV /home/ilan/python_project/non-generic-name
_python # CHECK:  3.11.5 (non-generic-name)

set -lx VIRTUAL_ENV /home/ilan/python_project/venv
_python # CHECK:  3.11.5 (python_project)

set -lx VIRTUAL_ENV /home/ilan/.local/share/virtualenvs/pipenv_project-EwRYuc3l
_python # CHECK:  3.11.5 (pipenv_project)

set -l python_directory (mktemp -d)
cd $python_directory

set -lx VIRTUAL_ENV
echo >requirements.txt
_python # CHECK:  3.11.5
20 changes: 0 additions & 20 deletions tests/_tide_item_virtual_env.test.fish

This file was deleted.

0 comments on commit 10a1fab

Please sign in to comment.