diff --git a/functions/_tide_item_python.fish b/functions/_tide_item_python.fish new file mode 100644 index 00000000..2d9e52b3 --- /dev/null +++ b/functions/_tide_item_python.fish @@ -0,0 +1,20 @@ +function _tide_item_python + if test -n "$VIRTUAL_ENV" + python --version | string match -qr "(?[\d.]+)" + + string match -qr "^.*/(?.*)/(?.*)" $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 + _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 "(?[\d.]+)" + _tide_print_item python $tide_python_icon' ' $v + end +end diff --git a/functions/_tide_item_virtual_env.fish b/functions/_tide_item_virtual_env.fish deleted file mode 100644 index 0f20ceec..00000000 --- a/functions/_tide_item_virtual_env.fish +++ /dev/null @@ -1,11 +0,0 @@ -function _tide_item_virtual_env - test -n "$VIRTUAL_ENV" && split_virtual_env=(string split / "$VIRTUAL_ENV") if test $split_virtual_env[-2] = virtualenvs - # 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. - _tide_print_item virtual_env $tide_virtual_env_icon' ' (string split -r -m1 - "$split_virtual_env[-1]")[1] - else if contains -- $split_virtual_env[-1] virtualenv venv .venv env # avoid generic names - _tide_print_item virtual_env $tide_virtual_env_icon' ' $split_virtual_env[-2] - else - _tide_print_item virtual_env $tide_virtual_env_icon' ' $split_virtual_env[-1] - end -end diff --git a/functions/_tide_remove_unusable_items.fish b/functions/_tide_remove_unusable_items.fish index 2ca028c6..5a425554 100644 --- a/functions/_tide_remove_unusable_items.fish +++ b/functions/_tide_remove_unusable_items.fish @@ -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 diff --git a/functions/tide/configure/configs/classic.fish b/functions/tide/configure/configs/classic.fish index a0f29791..86d2298a 100644 --- a/functions/tide/configure/configs/classic.fish +++ b/functions/tide/configure/configs/classic.fish @@ -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  @@ -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 diff --git a/functions/tide/configure/configs/classic_16color.fish b/functions/tide/configure/configs/classic_16color.fish index 037ecb0d..932279a0 100644 --- a/functions/tide/configure/configs/classic_16color.fish +++ b/functions/tide/configure/configs/classic_16color.fish @@ -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 @@ -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 diff --git a/functions/tide/configure/configs/lean.fish b/functions/tide/configure/configs/lean.fish index bf276302..8208e6ed 100644 --- a/functions/tide/configure/configs/lean.fish +++ b/functions/tide/configure/configs/lean.fish @@ -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 ' ' @@ -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 diff --git a/functions/tide/configure/configs/lean_16color.fish b/functions/tide/configure/configs/lean_16color.fish index 49e48b42..5a1f7265 100644 --- a/functions/tide/configure/configs/lean_16color.fish +++ b/functions/tide/configure/configs/lean_16color.fish @@ -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 @@ -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 diff --git a/functions/tide/configure/configs/rainbow.fish b/functions/tide/configure/configs/rainbow.fish index b827dfb7..241895c0 100644 --- a/functions/tide/configure/configs/rainbow.fish +++ b/functions/tide/configure/configs/rainbow.fish @@ -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  @@ -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 diff --git a/functions/tide/configure/configs/rainbow_16color.fish b/functions/tide/configure/configs/rainbow_16color.fish index d6097615..148f3dfe 100644 --- a/functions/tide/configure/configs/rainbow_16color.fish +++ b/functions/tide/configure/configs/rainbow_16color.fish @@ -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 @@ -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 diff --git a/functions/tide/configure/icons.fish b/functions/tide/configure/icons.fish index 7b1c2902..f2d405bc 100644 --- a/functions/tide/configure/icons.fish +++ b/functions/tide/configure/icons.fish @@ -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  @@ -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 󰌠 diff --git a/tests/_tide_item_python.test.fish b/tests/_tide_item_python.test.fish new file mode 100644 index 00000000..f0b3ff8d --- /dev/null +++ b/tests/_tide_item_python.test.fish @@ -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 diff --git a/tests/_tide_item_virtual_env.test.fish b/tests/_tide_item_virtual_env.test.fish deleted file mode 100644 index 2ca93041..00000000 --- a/tests/_tide_item_virtual_env.test.fish +++ /dev/null @@ -1,20 +0,0 @@ -# RUN: %fish %s -_tide_parent_dirs - -function _virtual_env - _tide_decolor (_tide_item_virtual_env) -end - -set -lx tide_virtual_env_icon  - -set -lx VIRTUAL_ENV -_virtual_env # CHECK: - -set -lx VIRTUAL_ENV /home/ilan/python_project/non-generic-name -_virtual_env # CHECK:  non-generic-name - -set -lx VIRTUAL_ENV /home/ilan/python_project/venv -_virtual_env # CHECK:  python_project - -set -lx VIRTUAL_ENV /home/ilan/.local/share/virtualenvs/pipenv_project-EwRYuc3l -_virtual_env # CHECK:  pipenv_project