From 6a9d3e2749f0cc109604167ec9497ccda5c62d98 Mon Sep 17 00:00:00 2001 From: Branch Vincent Date: Sat, 1 Apr 2023 14:39:02 -0700 Subject: [PATCH] add gcloud (#396) * add gcloud * use named capture group --- functions/_tide_item_gcloud.fish | 8 +++++++ functions/_tide_remove_unusable_items.fish | 2 +- functions/tide/configure/configs/classic.fish | 5 +++- .../configure/configs/classic_16color.fish | 2 ++ functions/tide/configure/configs/lean.fish | 5 +++- .../tide/configure/configs/lean_16color.fish | 2 ++ functions/tide/configure/configs/rainbow.fish | 5 +++- .../configure/configs/rainbow_16color.fish | 2 ++ tests/_tide_item_gcloud.test.fish | 23 +++++++++++++++++++ 9 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 functions/_tide_item_gcloud.fish create mode 100644 tests/_tide_item_gcloud.test.fish diff --git a/functions/_tide_item_gcloud.fish b/functions/_tide_item_gcloud.fish new file mode 100644 index 0000000..b2b07d5 --- /dev/null +++ b/functions/_tide_item_gcloud.fish @@ -0,0 +1,8 @@ +function _tide_item_gcloud + set -q CLOUDSDK_CONFIG || set -l CLOUDSDK_CONFIG ~/.config/gcloud + path is $CLOUDSDK_CONFIG/active_config \ + && read -l config <$CLOUDSDK_CONFIG/active_config \ + && path is $CLOUDSDK_CONFIG/configurations/config_$config \ + && string match -qr '^\s*project\s*=\s*(?.*)' <$CLOUDSDK_CONFIG/configurations/config_$config \ + && _tide_print_item gcloud $tide_gcloud_icon' ' $project +end diff --git a/functions/_tide_remove_unusable_items.fish b/functions/_tide_remove_unusable_items.fish index 469150d..a5dbe52 100644 --- a/functions/_tide_remove_unusable_items.fish +++ b/functions/_tide_remove_unusable_items.fish @@ -1,7 +1,7 @@ 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 chruby crystal distrobox docker elixir git go java kubectl nix_shell node php pulumi rustc terraform toolbox virtual_env + for item in aws chruby crystal distrobox docker elixir gcloud git go java kubectl nix_shell node php pulumi rustc terraform toolbox virtual_env set -l cli_names $item switch $item case distrobox # there is no 'distrobox' command inside the container diff --git a/functions/tide/configure/configs/classic.fish b/functions/tide/configure/configs/classic.fish index a41fca5..065bfe4 100644 --- a/functions/tide/configure/configs/classic.fish +++ b/functions/tide/configure/configs/classic.fish @@ -34,6 +34,9 @@ tide_docker_icon  tide_elixir_bg_color 444444 tide_elixir_color 4E2A8E tide_elixir_icon  +tide_gcloud_bg_color 444444 +tide_gcloud_color 4285F4 +tide_gcloud_icon  tide_git_bg_color 444444 tide_git_bg_color_unstable 444444 tide_git_bg_color_urgent 444444 @@ -99,7 +102,7 @@ tide_pwd_icon_home tide_pwd_icon_unwritable  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_right_prompt_frame_enabled true -tide_right_prompt_items status cmd_duration context jobs node virtual_env rustc java php pulumi chruby go kubectl distrobox toolbox terraform aws nix_shell crystal elixir +tide_right_prompt_items status cmd_duration context jobs node virtual_env rustc java php pulumi chruby 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  diff --git a/functions/tide/configure/configs/classic_16color.fish b/functions/tide/configure/configs/classic_16color.fish index d44992e..a39ef74 100644 --- a/functions/tide/configure/configs/classic_16color.fish +++ b/functions/tide/configure/configs/classic_16color.fish @@ -18,6 +18,8 @@ tide_docker_bg_color black tide_docker_color blue tide_elixir_bg_color black tide_elixir_color magenta +tide_gcloud_bg_color black +tide_gcloud_color blue tide_git_bg_color black tide_git_bg_color_unstable black tide_git_bg_color_urgent black diff --git a/functions/tide/configure/configs/lean.fish b/functions/tide/configure/configs/lean.fish index feffd2b..75c8e34 100644 --- a/functions/tide/configure/configs/lean.fish +++ b/functions/tide/configure/configs/lean.fish @@ -34,6 +34,9 @@ tide_docker_icon  tide_elixir_bg_color normal tide_elixir_color 4E2A8E tide_elixir_icon  +tide_gcloud_bg_color normal +tide_gcloud_color 4285F4 +tide_gcloud_icon  tide_git_bg_color normal tide_git_bg_color_unstable normal tide_git_bg_color_urgent normal @@ -99,7 +102,7 @@ tide_pwd_icon_home tide_pwd_icon_unwritable  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_right_prompt_frame_enabled false -tide_right_prompt_items status cmd_duration context jobs node virtual_env rustc java php pulumi chruby go kubectl distrobox toolbox terraform aws nix_shell crystal elixir +tide_right_prompt_items status cmd_duration context jobs node virtual_env rustc java php pulumi chruby 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 ' ' diff --git a/functions/tide/configure/configs/lean_16color.fish b/functions/tide/configure/configs/lean_16color.fish index 0b49799..3b2b35e 100644 --- a/functions/tide/configure/configs/lean_16color.fish +++ b/functions/tide/configure/configs/lean_16color.fish @@ -18,6 +18,8 @@ tide_docker_bg_color normal tide_docker_color blue tide_elixir_bg_color normal tide_elixir_color magenta +tide_gcloud_bg_color normal +tide_gcloud_color blue tide_git_bg_color normal tide_git_bg_color_unstable normal tide_git_bg_color_urgent normal diff --git a/functions/tide/configure/configs/rainbow.fish b/functions/tide/configure/configs/rainbow.fish index 9f4a7b6..e485e44 100644 --- a/functions/tide/configure/configs/rainbow.fish +++ b/functions/tide/configure/configs/rainbow.fish @@ -34,6 +34,9 @@ tide_docker_icon  tide_elixir_bg_color 4E2A8E tide_elixir_color 000000 tide_elixir_icon  +tide_gcloud_bg_color 4285F4 +tide_gcloud_color 000000 +tide_gcloud_icon  tide_git_bg_color 4E9A06 tide_git_bg_color_unstable C4A000 tide_git_bg_color_urgent CC0000 @@ -99,7 +102,7 @@ tide_pwd_icon_home tide_pwd_icon_unwritable  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_right_prompt_frame_enabled true -tide_right_prompt_items status cmd_duration context jobs node virtual_env rustc java php pulumi chruby go kubectl distrobox toolbox terraform aws nix_shell crystal elixir +tide_right_prompt_items status cmd_duration context jobs node virtual_env rustc java php pulumi chruby 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  diff --git a/functions/tide/configure/configs/rainbow_16color.fish b/functions/tide/configure/configs/rainbow_16color.fish index c408ebe..47836ce 100644 --- a/functions/tide/configure/configs/rainbow_16color.fish +++ b/functions/tide/configure/configs/rainbow_16color.fish @@ -18,6 +18,8 @@ tide_docker_bg_color blue tide_docker_color black tide_elixir_bg_color magenta tide_elixir_color black +tide_gcloud_bg_color blue +tide_gcloud_color black tide_git_bg_color green tide_git_bg_color_unstable yellow tide_git_bg_color_urgent red diff --git a/tests/_tide_item_gcloud.test.fish b/tests/_tide_item_gcloud.test.fish new file mode 100644 index 0000000..3e5ef32 --- /dev/null +++ b/tests/_tide_item_gcloud.test.fish @@ -0,0 +1,23 @@ +# RUN: %fish %s +_tide_parent_dirs + +function _gcloud + _tide_decolor (_tide_item_gcloud) +end + +set -lx tide_gcloud_icon G +set -l tmpdir (mktemp -d) +cd $tmpdir +set -lx HOME $tmpdir + +_gcloud # CHECK: + +mkdir -p $tmpdir/.config/gcloud +echo default >$tmpdir/.config/gcloud/active_config +_gcloud # CHECK: + +mkdir -p $tmpdir/.config/gcloud/configurations +echo "project = test" >$tmpdir/.config/gcloud/configurations/config_default +_gcloud # CHECK: G test + +command rm -r $tmpdir