From d4080e434ea2133b2156cba0035429b25f6b6f56 Mon Sep 17 00:00:00 2001 From: Dor Munis <5811812+dormunis@users.noreply.github.com> Date: Fri, 12 May 2023 19:02:51 +0300 Subject: [PATCH 1/2] Added terraform workspace support --- scripts/dracula.sh | 5 +++++ scripts/terraform.sh | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100755 scripts/terraform.sh diff --git a/scripts/dracula.sh b/scripts/dracula.sh index a2bff10..af0b222 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -8,6 +8,7 @@ source $current_dir/utils.sh main() { # set configuration option variables + terraform_label=$(get_tmux_option "@dracula-terraform-label" "") show_fahrenheit=$(get_tmux_option "@dracula-show-fahrenheit" true) show_location=$(get_tmux_option "@dracula-show-location" true) fixed_location=$(get_tmux_option "@dracula-fixed-location") @@ -197,6 +198,10 @@ main() IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-kubernetes-context-colors" "cyan dark_gray") script="#($current_dir/kubernetes_context.sh $show_kubernetes_context_label)" + elif [ $plugin = "terraform" ]; then + IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-terraform-colors" "light_purple dark_gray") + script="#($current_dir/terraform.sh $terraform_label)" + elif [ $plugin = "weather" ]; then IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-weather-colors" "orange dark_gray") script="#($current_dir/weather_wrapper.sh $show_fahrenheit $show_location $fixed_location)" diff --git a/scripts/terraform.sh b/scripts/terraform.sh new file mode 100755 index 0000000..72e144c --- /dev/null +++ b/scripts/terraform.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# setting the locale, some users have issues with different locales, this forces the correct one +export LC_ALL=en_US.UTF-8 + +label=$1 + +current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +source $current_dir/utils.sh + +main() { + # storing the refresh rate in the variable RATE, default is 5 + RATE=$(get_tmux_option "@dracula-refresh-rate" 5) + OUTPUT_STRING="N/A" + terraform_dir="$(tmux display-message -p '#{pane_current_path}')/.terraform" + if [ -d $terraform_dir ]; then + current_workspace=$(terraform workspace show 2>/dev/null) + OUTPUT_STRING="${current_workspace}" + fi + if [ "$label" = "" ] + then + echo "⚙️ ${OUTPUT_STRING}" + else + echo "⚙️ ${label} ${OUTPUT_STRING}" + fi + + sleep $RATE +} + +# run the main driver +main From 6fe855290f2d92ed91c165d2e6f925c12d21f901 Mon Sep 17 00:00:00 2001 From: jonathanforhan Date: Fri, 12 May 2023 13:35:49 -0400 Subject: [PATCH 2/2] fix bug with multi-word cwd --- scripts/cwd.sh | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/scripts/cwd.sh b/scripts/cwd.sh index cfae694..5da448c 100755 --- a/scripts/cwd.sh +++ b/scripts/cwd.sh @@ -1,29 +1,24 @@ #!/usr/bin/env bash # return current working directory of tmux pane -getPaneDir() -{ +getPaneDir() { nextone="false" - for i in $(tmux list-panes -F "#{pane_active} #{pane_current_path}"); - do - if [ "$nextone" == "true" ]; then - echo $i - return - fi - if [ "$i" == "1" ]; then - nextone="true" - fi + ret="" + for i in $(tmux list-panes -F "#{pane_active} #{pane_current_path}"); do + [ "$i" == "1" ] && nextone="true" && continue + [ "$i" == "0" ] && nextone="false" + [ "$nextone" == "true" ] && ret+="$i " done + echo "${ret%?}" } -main() -{ +main() { path=$(getPaneDir) # change '/home/user' to '~' - cwd=$(echo $path | sed "s;$HOME;~;g") + cwd="${path/"$HOME"/'~'}" - echo $cwd + echo "$cwd" } #run main driver program