From 3787c725f7f6a0253f59a2c0e9fde03202689c6c Mon Sep 17 00:00:00 2001 From: radek-sprta Date: Wed, 22 Sep 2021 01:02:08 +0200 Subject: [PATCH] Add Terraform item (#203) * Add Terraform item * Do not show default workspace in Terraform prompt * Add terraform to tide_right_prompt_items * Add terraform to _tide_remove_unusable_items * Fix test, use read, format Co-authored-by: Ilan Cosman --- functions/_tide_item_terraform.fish | 6 ++++++ 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_terraform.test.fish | 19 +++++++++++++++++++ 9 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 functions/_tide_item_terraform.fish create mode 100644 tests/_tide_item_terraform.test.fish diff --git a/functions/_tide_item_terraform.fish b/functions/_tide_item_terraform.fish new file mode 100644 index 0000000..60fd3fb --- /dev/null +++ b/functions/_tide_item_terraform.fish @@ -0,0 +1,6 @@ +function _tide_item_terraform + if test -d .terraform + terraform workspace show | read -l workspace + test $workspace != default && _tide_print_item terraform $tide_terraform_icon' ' $workspace + end +end diff --git a/functions/_tide_remove_unusable_items.fish b/functions/_tide_remove_unusable_items.fish index 239d6e3..d885cf4 100644 --- a/functions/_tide_remove_unusable_items.fish +++ b/functions/_tide_remove_unusable_items.fish @@ -1,6 +1,6 @@ function _tide_remove_unusable_items # Remove tool-specific items for tools the machine doesn't have installed - for item in chruby git go kubectl node php rustc virtual_env + for item in chruby git go kubectl node php rustc terraform virtual_env set -l cli_names $item switch $item case virtual_env diff --git a/functions/tide/configure/configs/classic.fish b/functions/tide/configure/configs/classic.fish index c8ce56d..fcbe1c4 100644 --- a/functions/tide/configure/configs/classic.fish +++ b/functions/tide/configure/configs/classic.fish @@ -67,7 +67,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 php chruby go kubectl vi_mode +tide_right_prompt_items status cmd_duration context jobs node virtual_env rustc php chruby go kubectl terraform vi_mode tide_right_prompt_prefix '' tide_right_prompt_separator_diff_color '' tide_right_prompt_separator_same_color '' @@ -85,6 +85,9 @@ tide_status_color $_tide_color_dark_green tide_status_color_failure D70000 tide_status_icon '✔' tide_status_icon_failure '✘' +tide_terraform_bg_color 444444 +tide_terraform_color 844FBA +tide_terraform_icon tide_time_bg_color 444444 tide_time_color 5F8787 tide_time_format '%T' diff --git a/functions/tide/configure/configs/classic_16color.fish b/functions/tide/configure/configs/classic_16color.fish index 88e8869..d3a505f 100644 --- a/functions/tide/configure/configs/classic_16color.fish +++ b/functions/tide/configure/configs/classic_16color.fish @@ -45,6 +45,8 @@ tide_status_bg_color black tide_status_bg_color_failure black tide_status_color green tide_status_color_failure red +tide_terraform_bg_color black +tide_terraform_color magenta tide_time_bg_color black tide_time_color brblack tide_vi_mode_bg_color_default black diff --git a/functions/tide/configure/configs/lean.fish b/functions/tide/configure/configs/lean.fish index 2cc4f47..ba45973 100644 --- a/functions/tide/configure/configs/lean.fish +++ b/functions/tide/configure/configs/lean.fish @@ -67,7 +67,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 php chruby go kubectl +tide_right_prompt_items status cmd_duration context jobs node virtual_env rustc php chruby go kubectl terraform tide_right_prompt_prefix ' ' tide_right_prompt_separator_diff_color ' ' tide_right_prompt_separator_same_color ' ' @@ -85,6 +85,9 @@ tide_status_color $_tide_color_dark_green tide_status_color_failure D70000 tide_status_icon '✔' tide_status_icon_failure '✘' +tide_terraform_bg_color normal +tide_terraform_color 844FBA +tide_terraform_icon tide_time_bg_color normal tide_time_color 5F8787 tide_time_format '%T' diff --git a/functions/tide/configure/configs/lean_16color.fish b/functions/tide/configure/configs/lean_16color.fish index 5458ece..ead6e6f 100644 --- a/functions/tide/configure/configs/lean_16color.fish +++ b/functions/tide/configure/configs/lean_16color.fish @@ -45,6 +45,8 @@ tide_status_bg_color normal tide_status_bg_color_failure normal tide_status_color green tide_status_color_failure red +tide_terraform_bg_color normal +tide_terraform_color magenta tide_time_bg_color normal tide_time_color brblack tide_vi_mode_bg_color_default normal diff --git a/functions/tide/configure/configs/rainbow.fish b/functions/tide/configure/configs/rainbow.fish index c761f0e..39afcbc 100644 --- a/functions/tide/configure/configs/rainbow.fish +++ b/functions/tide/configure/configs/rainbow.fish @@ -67,7 +67,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 php chruby go kubectl vi_mode +tide_right_prompt_items status cmd_duration context jobs node virtual_env rustc php chruby go kubectl terraform vi_mode tide_right_prompt_prefix '' tide_right_prompt_separator_diff_color '' tide_right_prompt_separator_same_color '' @@ -85,6 +85,9 @@ tide_status_color 4E9A06 tide_status_color_failure FFFF00 tide_status_icon '✔' tide_status_icon_failure '✘' +tide_terraform_bg_color 800080 +tide_terraform_color 000000 +tide_terraform_icon tide_time_bg_color D3D7CF tide_time_color 000000 tide_time_format '%T' diff --git a/functions/tide/configure/configs/rainbow_16color.fish b/functions/tide/configure/configs/rainbow_16color.fish index 5014e94..c38b6c5 100644 --- a/functions/tide/configure/configs/rainbow_16color.fish +++ b/functions/tide/configure/configs/rainbow_16color.fish @@ -45,6 +45,8 @@ tide_status_bg_color black tide_status_bg_color_failure red tide_status_color green tide_status_color_failure bryellow +tide_terraform_bg_color magenta +tide_terraform_color black tide_time_bg_color white tide_time_color black tide_vi_mode_bg_color_default green diff --git a/tests/_tide_item_terraform.test.fish b/tests/_tide_item_terraform.test.fish new file mode 100644 index 0000000..a6e75b5 --- /dev/null +++ b/tests/_tide_item_terraform.test.fish @@ -0,0 +1,19 @@ +# RUN: %fish %s + +function _terraform + _tide_decolor (_tide_item_terraform) +end + +set -l terraformDir (mktemp -d) +cd $terraformDir + +mock terraform "workspace show" "echo default" +_terraform # CHECK: + +mkdir .terraform +_terraform # CHECK: + +mock terraform "workspace show" "echo test" +_terraform # CHECK: test + +rm -r $terraformDir