From 78397ad598673fe09036c3002d55c0b45dfa90e7 Mon Sep 17 00:00:00 2001 From: Ofir Shtrull Date: Thu, 27 Feb 2020 14:40:57 +0200 Subject: [PATCH 1/5] Add terraform workspace to prompt --- themes/powerline-multiline/README.md | 2 ++ .../powerline-multiline/powerline-multiline.theme.bash | 3 +++ themes/powerline-naked/README.md | 1 + themes/powerline-naked/powerline-naked.theme.bash | 3 +++ themes/powerline-plain/README.md | 1 + themes/powerline-plain/powerline-plain.theme.bash | 3 +++ themes/powerline/README.md | 1 + themes/powerline/powerline.base.bash | 9 +++++++++ themes/powerline/powerline.theme.bash | 3 +++ 9 files changed, 26 insertions(+) diff --git a/themes/powerline-multiline/README.md b/themes/powerline-multiline/README.md index cbc585e2..3debf1d3 100644 --- a/themes/powerline-multiline/README.md +++ b/themes/powerline-multiline/README.md @@ -66,6 +66,8 @@ The contents of both prompt sides can be "reordered", all the "segments" (every * `ruby` - Current ruby version if using `rvm` * `node` - Current node version (only `nvm` is supported) * `scm` - Version control information, `git` +* `terraform` - Current terraform workspace +* `k8s_context` - Show current kubernetes context * `user_info` - Current user * `wd` - Working directory, like `cwd` but doesn't show the full folder hierarchy, only the directory you're currently in. diff --git a/themes/powerline-multiline/powerline-multiline.theme.bash b/themes/powerline-multiline/powerline-multiline.theme.bash index f76c5969..54651cb6 100644 --- a/themes/powerline-multiline/powerline-multiline.theme.bash +++ b/themes/powerline-multiline/powerline-multiline.theme.bash @@ -49,6 +49,9 @@ RBENV_THEME_PROMPT_SUFFIX="" RUBY_THEME_PROMPT_COLOR=${POWERLINE_RUBY_COLOR:=161} RUBY_CHAR=${POWERLINE_RUBY_CHAR:="❲r❳ "} +TERRAFORM_THEME_PROMPT_COLOR=${POWERLINE_TERRAFORM_COLOR:=161} +TERRAFORM_CHAR=${POWERLINE_TERRAFORM_CHAR:="❲t❳ "} + KUBERNETES_CONTEXT_THEME_CHAR=${POWERLINE_KUBERNETES_CONTEXT_CHAR:="⎈ "} KUBERNETES_CONTEXT_THEME_PROMPT_COLOR=${POWERLINE_KUBERNETES_CONTEXT_COLOR:=26} diff --git a/themes/powerline-naked/README.md b/themes/powerline-naked/README.md index 296c30ab..ec3b8fac 100644 --- a/themes/powerline-naked/README.md +++ b/themes/powerline-naked/README.md @@ -60,6 +60,7 @@ The contents of the prompt can be "reordered", all the "segments" (every piece o * `ruby` - Current ruby version if using `rvm` * `node` - Current node version (only `nvm` is supported) * `scm` - Version control information, `git` +* `terraform` - Current terraform workspace * `user_info` - Current user * `wd` - Working directory, like `cwd` but doesn't show the full folder hierarchy, only the directory you're currently in. diff --git a/themes/powerline-naked/powerline-naked.theme.bash b/themes/powerline-naked/powerline-naked.theme.bash index dfa3eb1d..bf314aca 100644 --- a/themes/powerline-naked/powerline-naked.theme.bash +++ b/themes/powerline-naked/powerline-naked.theme.bash @@ -47,6 +47,9 @@ RUBY_CHAR=${POWERLINE_RUBY_CHAR:="❲r❳ "} KUBERNETES_CONTEXT_THEME_CHAR=${POWERLINE_KUBERNETES_CONTEXT_CHAR:="⎈ "} KUBERNETES_CONTEXT_THEME_PROMPT_COLOR=${POWERLINE_KUBERNETES_CONTEXT_COLOR:=26} +TERRAFORM_THEME_PROMPT_COLOR=${POWERLINE_TERRAFORM_COLOR:=161} +TERRAFORM_CHAR=${POWERLINE_TERRAFORM_CHAR:="❲t❳ "} + AWS_PROFILE_CHAR=${POWERLINE_AWS_PROFILE_CHAR:="❲aws❳ "} AWS_PROFILE_PROMPT_COLOR=${POWERLINE_AWS_PROFILE_COLOR:=208} diff --git a/themes/powerline-plain/README.md b/themes/powerline-plain/README.md index 2470a718..7ccb1eeb 100644 --- a/themes/powerline-plain/README.md +++ b/themes/powerline-plain/README.md @@ -52,6 +52,7 @@ The contents of the prompt can be "reordered", all the "segments" (every piece o * `hostname` - Host name of machine * `in_vim` - Show identifier if running in `:terminal` from vim * `k8s_context` - Show current kubernetes context +* `terraform` - Current terraform workspace * `last_status` - Exit status of last run command * `python_venv` - Python virtual environment information (`virtualenv`, `venv` and `conda` supported) diff --git a/themes/powerline-plain/powerline-plain.theme.bash b/themes/powerline-plain/powerline-plain.theme.bash index 3ead67fe..0a353ca5 100644 --- a/themes/powerline-plain/powerline-plain.theme.bash +++ b/themes/powerline-plain/powerline-plain.theme.bash @@ -43,6 +43,9 @@ RUBY_CHAR=${POWERLINE_RUBY_CHAR:="💎 "} KUBERNETES_CONTEXT_THEME_CHAR=${POWERLINE_KUBERNETES_CONTEXT_CHAR:="⎈ "} KUBERNETES_CONTEXT_THEME_PROMPT_COLOR=${POWERLINE_KUBERNETES_CONTEXT_COLOR:=26} +TERRAFORM_THEME_PROMPT_COLOR=${POWERLINE_TERRAFORM_COLOR:=161} +TERRAFORM_CHAR=${POWERLINE_TERRAFORM_CHAR:="❲t❳ "} + AWS_PROFILE_CHAR=${POWERLINE_AWS_PROFILE_CHAR:="❲aws❳ "} AWS_PROFILE_PROMPT_COLOR=${POWERLINE_AWS_PROFILE_COLOR:=208} diff --git a/themes/powerline/README.md b/themes/powerline/README.md index 2076336f..5f0d69dd 100644 --- a/themes/powerline/README.md +++ b/themes/powerline/README.md @@ -67,6 +67,7 @@ The contents of the prompt can be "reordered", all the "segments" (every piece o * `node` - Current node version (only `nvm` is supported) * `scm` - Version control information, `git` * `user_info` - Current user +* `terraform` - Current terraform workspace * `wd` - Working directory, like `cwd` but doesn't show the full folder hierarchy, only the directory you're currently in. * `shlvl` - Show the current shell level (based on `SHLVL` environment variable), but only if you are not in root shell diff --git a/themes/powerline/powerline.base.bash b/themes/powerline/powerline.base.bash index c3fac913..26fb0d3f 100644 --- a/themes/powerline/powerline.base.bash +++ b/themes/powerline/powerline.base.bash @@ -41,6 +41,15 @@ function __powerline_user_info_prompt { [[ -n "${user_info}" ]] && echo "${user_info}|${color}" } +function __powerline_terraform_prompt() { + local terraform_workspace="" + + if [ -d .terraform ]; then + terraform_workspace="$(command terraform workspace show 2>/dev/null)" + [[ -n "${terraform_workspace}" ]] && echo "${TERRAFORM_CHAR}${terraform_workspace}|${TERRAFORM_THEME_PROMPT_COLOR}" + fi +} + function __powerline_node_prompt { local node_version="" diff --git a/themes/powerline/powerline.theme.bash b/themes/powerline/powerline.theme.bash index f3ef9a32..d897c7c8 100644 --- a/themes/powerline/powerline.theme.bash +++ b/themes/powerline/powerline.theme.bash @@ -45,6 +45,9 @@ RBENV_THEME_PROMPT_SUFFIX="" RUBY_THEME_PROMPT_COLOR=${POWERLINE_RUBY_COLOR:=161} RUBY_CHAR=${POWERLINE_RUBY_CHAR:="❲r❳ "} +TERRAFORM_THEME_PROMPT_COLOR=${POWERLINE_TERRAFORM_COLOR:=161} +TERRAFORM_CHAR=${POWERLINE_TERRAFORM_CHAR:="❲t❳ "} + KUBERNETES_CONTEXT_THEME_CHAR=${POWERLINE_KUBERNETES_CONTEXT_CHAR:="⎈ "} KUBERNETES_CONTEXT_THEME_PROMPT_COLOR=${POWERLINE_KUBERNETES_CONTEXT_COLOR:=26} From 936a79f6190e1d620d843b566d035d627c92b189 Mon Sep 17 00:00:00 2001 From: Ofir Shtrull Date: Thu, 27 Feb 2020 20:53:35 +0200 Subject: [PATCH 2/5] now usable by all prompts --- themes/base.theme.bash | 8 ++++++++ themes/powerline-multiline/README.md | 2 +- themes/powerline-naked/powerline-naked.base.bash | 9 +++++---- themes/powerline-naked/powerline-naked.theme.bash | 3 +++ themes/powerline-plain/README.md | 2 +- themes/powerline/README.md | 2 +- themes/powerline/powerline.base.bash | 9 +++++++++ 7 files changed, 28 insertions(+), 7 deletions(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index d193191e..d5858018 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -155,6 +155,14 @@ function scm_prompt_info_common { { [[ ${SCM} == ${SCM_SVN} ]] && svn_prompt_info && return; } || true } +function terraform_workspace_prompt { + if _command_exists terraform ; then + if [ -d .terraform ]; then + echo -e "$(terraform workspace show 2>/dev/null)" + fi + fi +} + function git_prompt_minimal_info { SCM_STATE=${SCM_THEME_PROMPT_CLEAN} diff --git a/themes/powerline-multiline/README.md b/themes/powerline-multiline/README.md index 3debf1d3..f4a1fab8 100644 --- a/themes/powerline-multiline/README.md +++ b/themes/powerline-multiline/README.md @@ -60,6 +60,7 @@ The contents of both prompt sides can be "reordered", all the "segments" (every * `cwd` - Current working directory including full folder hierarchy (c.f. `wd`) * `hostname` - Host name of machine * `in_vim` - Show identifier if running in `:terminal` from vim +* `k8s_context` - Show current kubernetes context * `last_status` - Exit status of last run command * `python_venv` - Python virtual environment information (`virtualenv`, `venv` and `conda` supported) @@ -67,7 +68,6 @@ The contents of both prompt sides can be "reordered", all the "segments" (every * `node` - Current node version (only `nvm` is supported) * `scm` - Version control information, `git` * `terraform` - Current terraform workspace -* `k8s_context` - Show current kubernetes context * `user_info` - Current user * `wd` - Working directory, like `cwd` but doesn't show the full folder hierarchy, only the directory you're currently in. diff --git a/themes/powerline-naked/powerline-naked.base.bash b/themes/powerline-naked/powerline-naked.base.bash index 16b633be..d4a2e648 100644 --- a/themes/powerline-naked/powerline-naked.base.bash +++ b/themes/powerline-naked/powerline-naked.base.bash @@ -1,7 +1,8 @@ . "$BASH_IT/themes/powerline/powerline.base.bash" -function __powerline_left_segment { - local OLD_IFS="${IFS}"; IFS="|" +function __powerline_left_segment() { + local OLD_IFS="${IFS}" + IFS="|" local params=( $1 ) IFS="${OLD_IFS}" local separator="" @@ -25,9 +26,9 @@ function __powerline_left_segment { LEFT_PROMPT+="$(set_color ${params[1]} -)${pad_before_segment}${params[0]}${normal}" LAST_SEGMENT_COLOR=${params[1]} - (( SEGMENTS_AT_LEFT += 1 )) + ((SEGMENTS_AT_LEFT += 1)) } -function __powerline_left_last_segment_padding { +function __powerline_left_last_segment_padding() { LEFT_PROMPT+="$(set_color ${LAST_SEGMENT_COLOR} -) ${normal}" } diff --git a/themes/powerline-naked/powerline-naked.theme.bash b/themes/powerline-naked/powerline-naked.theme.bash index bf314aca..93127c44 100644 --- a/themes/powerline-naked/powerline-naked.theme.bash +++ b/themes/powerline-naked/powerline-naked.theme.bash @@ -17,6 +17,9 @@ USER_INFO_SSH_CHAR=${POWERLINE_USER_INFO_SSH_CHAR:=" "} USER_INFO_THEME_PROMPT_COLOR=${POWERLINE_USER_INFO_COLOR:=240} USER_INFO_THEME_PROMPT_COLOR_SUDO=${POWERLINE_USER_INFO_COLOR_SUDO:=202} +TERRAFORM_THEME_PROMPT_COLOR=${POWERLINE_TERRAFORM_COLOR:=161} +TERRAFORM_CHAR=${POWERLINE_TERRAFORM_CHAR:="❲t❳ "} + PYTHON_VENV_CHAR=${POWERLINE_PYTHON_VENV_CHAR:="❲p❳ "} CONDA_PYTHON_VENV_CHAR=${POWERLINE_CONDA_PYTHON_VENV_CHAR:="❲c❳ "} PYTHON_VENV_THEME_PROMPT_COLOR=${POWERLINE_PYTHON_VENV_COLOR:=35} diff --git a/themes/powerline-plain/README.md b/themes/powerline-plain/README.md index 7ccb1eeb..049c12f1 100644 --- a/themes/powerline-plain/README.md +++ b/themes/powerline-plain/README.md @@ -52,13 +52,13 @@ The contents of the prompt can be "reordered", all the "segments" (every piece o * `hostname` - Host name of machine * `in_vim` - Show identifier if running in `:terminal` from vim * `k8s_context` - Show current kubernetes context -* `terraform` - Current terraform workspace * `last_status` - Exit status of last run command * `python_venv` - Python virtual environment information (`virtualenv`, `venv` and `conda` supported) * `ruby` - Current ruby version if using `rvm` * `node` - Current node version (only `nvm` is supported) * `scm` - Version control information, `git` +* `terraform` - Current terraform workspace * `user_info` - Current user * `wd` - Working directory, like `cwd` but doesn't show the full folder hierarchy, only the directory you're currently in. diff --git a/themes/powerline/README.md b/themes/powerline/README.md index 5f0d69dd..587e0788 100644 --- a/themes/powerline/README.md +++ b/themes/powerline/README.md @@ -66,8 +66,8 @@ The contents of the prompt can be "reordered", all the "segments" (every piece o * `ruby` - Current ruby version if using `rvm` * `node` - Current node version (only `nvm` is supported) * `scm` - Version control information, `git` -* `user_info` - Current user * `terraform` - Current terraform workspace +* `user_info` - Current user * `wd` - Working directory, like `cwd` but doesn't show the full folder hierarchy, only the directory you're currently in. * `shlvl` - Show the current shell level (based on `SHLVL` environment variable), but only if you are not in root shell diff --git a/themes/powerline/powerline.base.bash b/themes/powerline/powerline.base.bash index 26fb0d3f..f9a6d0d5 100644 --- a/themes/powerline/powerline.base.bash +++ b/themes/powerline/powerline.base.bash @@ -50,6 +50,15 @@ function __powerline_terraform_prompt() { fi } +function __powerline_terraform_prompt() { + local terraform_workspace="" + + if [ -d .terraform ]; then + terraform_workspace="$(terraform_workspace_prompt)" + [[ -n "${terraform_workspace}" ]] && echo "${TERRAFORM_CHAR}${terraform_workspace}|${TERRAFORM_THEME_PROMPT_COLOR}" + fi +} + function __powerline_node_prompt { local node_version="" From 84ad65c309d6df159454d2041b0822e177370928 Mon Sep 17 00:00:00 2001 From: Ofir Shtrull Date: Thu, 27 Feb 2020 21:52:21 +0200 Subject: [PATCH 3/5] cleanup --- themes/powerline-naked/powerline-naked.base.bash | 2 +- themes/powerline/powerline.base.bash | 11 +---------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/themes/powerline-naked/powerline-naked.base.bash b/themes/powerline-naked/powerline-naked.base.bash index d4a2e648..a4283b75 100644 --- a/themes/powerline-naked/powerline-naked.base.bash +++ b/themes/powerline-naked/powerline-naked.base.bash @@ -29,6 +29,6 @@ function __powerline_left_segment() { ((SEGMENTS_AT_LEFT += 1)) } -function __powerline_left_last_segment_padding() { +function __powerline_left_last_segment_padding { LEFT_PROMPT+="$(set_color ${LAST_SEGMENT_COLOR} -) ${normal}" } diff --git a/themes/powerline/powerline.base.bash b/themes/powerline/powerline.base.bash index f9a6d0d5..969b210d 100644 --- a/themes/powerline/powerline.base.bash +++ b/themes/powerline/powerline.base.bash @@ -41,16 +41,7 @@ function __powerline_user_info_prompt { [[ -n "${user_info}" ]] && echo "${user_info}|${color}" } -function __powerline_terraform_prompt() { - local terraform_workspace="" - - if [ -d .terraform ]; then - terraform_workspace="$(command terraform workspace show 2>/dev/null)" - [[ -n "${terraform_workspace}" ]] && echo "${TERRAFORM_CHAR}${terraform_workspace}|${TERRAFORM_THEME_PROMPT_COLOR}" - fi -} - -function __powerline_terraform_prompt() { +function __powerline_terraform_prompt { local terraform_workspace="" if [ -d .terraform ]; then From a578fa81e424844aac8bfc19fcc4b404c94a78e2 Mon Sep 17 00:00:00 2001 From: Ofir Shtrull Date: Thu, 27 Feb 2020 22:10:38 +0200 Subject: [PATCH 4/5] more cleanup --- themes/powerline-naked/powerline-naked.base.bash | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/themes/powerline-naked/powerline-naked.base.bash b/themes/powerline-naked/powerline-naked.base.bash index a4283b75..16b633be 100644 --- a/themes/powerline-naked/powerline-naked.base.bash +++ b/themes/powerline-naked/powerline-naked.base.bash @@ -1,8 +1,7 @@ . "$BASH_IT/themes/powerline/powerline.base.bash" -function __powerline_left_segment() { - local OLD_IFS="${IFS}" - IFS="|" +function __powerline_left_segment { + local OLD_IFS="${IFS}"; IFS="|" local params=( $1 ) IFS="${OLD_IFS}" local separator="" @@ -26,7 +25,7 @@ function __powerline_left_segment() { LEFT_PROMPT+="$(set_color ${params[1]} -)${pad_before_segment}${params[0]}${normal}" LAST_SEGMENT_COLOR=${params[1]} - ((SEGMENTS_AT_LEFT += 1)) + (( SEGMENTS_AT_LEFT += 1 )) } function __powerline_left_last_segment_padding { From 381a0069c34700986dbfd017191dd68a96d70929 Mon Sep 17 00:00:00 2001 From: Ofir Shtrull Date: Thu, 27 Feb 2020 23:32:43 +0200 Subject: [PATCH 5/5] changed order of params --- themes/powerline-naked/powerline-naked.theme.bash | 9 +++------ themes/powerline-plain/powerline-plain.theme.bash | 6 +++--- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/themes/powerline-naked/powerline-naked.theme.bash b/themes/powerline-naked/powerline-naked.theme.bash index 93127c44..5c5fed26 100644 --- a/themes/powerline-naked/powerline-naked.theme.bash +++ b/themes/powerline-naked/powerline-naked.theme.bash @@ -17,9 +17,6 @@ USER_INFO_SSH_CHAR=${POWERLINE_USER_INFO_SSH_CHAR:=" "} USER_INFO_THEME_PROMPT_COLOR=${POWERLINE_USER_INFO_COLOR:=240} USER_INFO_THEME_PROMPT_COLOR_SUDO=${POWERLINE_USER_INFO_COLOR_SUDO:=202} -TERRAFORM_THEME_PROMPT_COLOR=${POWERLINE_TERRAFORM_COLOR:=161} -TERRAFORM_CHAR=${POWERLINE_TERRAFORM_CHAR:="❲t❳ "} - PYTHON_VENV_CHAR=${POWERLINE_PYTHON_VENV_CHAR:="❲p❳ "} CONDA_PYTHON_VENV_CHAR=${POWERLINE_CONDA_PYTHON_VENV_CHAR:="❲c❳ "} PYTHON_VENV_THEME_PROMPT_COLOR=${POWERLINE_PYTHON_VENV_COLOR:=35} @@ -47,12 +44,12 @@ RBENV_THEME_PROMPT_SUFFIX="" RUBY_THEME_PROMPT_COLOR=${POWERLINE_RUBY_COLOR:=161} RUBY_CHAR=${POWERLINE_RUBY_CHAR:="❲r❳ "} -KUBERNETES_CONTEXT_THEME_CHAR=${POWERLINE_KUBERNETES_CONTEXT_CHAR:="⎈ "} -KUBERNETES_CONTEXT_THEME_PROMPT_COLOR=${POWERLINE_KUBERNETES_CONTEXT_COLOR:=26} - TERRAFORM_THEME_PROMPT_COLOR=${POWERLINE_TERRAFORM_COLOR:=161} TERRAFORM_CHAR=${POWERLINE_TERRAFORM_CHAR:="❲t❳ "} +KUBERNETES_CONTEXT_THEME_CHAR=${POWERLINE_KUBERNETES_CONTEXT_CHAR:="⎈ "} +KUBERNETES_CONTEXT_THEME_PROMPT_COLOR=${POWERLINE_KUBERNETES_CONTEXT_COLOR:=26} + AWS_PROFILE_CHAR=${POWERLINE_AWS_PROFILE_CHAR:="❲aws❳ "} AWS_PROFILE_PROMPT_COLOR=${POWERLINE_AWS_PROFILE_COLOR:=208} diff --git a/themes/powerline-plain/powerline-plain.theme.bash b/themes/powerline-plain/powerline-plain.theme.bash index 0a353ca5..942c411c 100644 --- a/themes/powerline-plain/powerline-plain.theme.bash +++ b/themes/powerline-plain/powerline-plain.theme.bash @@ -40,12 +40,12 @@ RBENV_THEME_PROMPT_SUFFIX="" RUBY_THEME_PROMPT_COLOR=${POWERLINE_RUBY_COLOR:=161} RUBY_CHAR=${POWERLINE_RUBY_CHAR:="💎 "} -KUBERNETES_CONTEXT_THEME_CHAR=${POWERLINE_KUBERNETES_CONTEXT_CHAR:="⎈ "} -KUBERNETES_CONTEXT_THEME_PROMPT_COLOR=${POWERLINE_KUBERNETES_CONTEXT_COLOR:=26} - TERRAFORM_THEME_PROMPT_COLOR=${POWERLINE_TERRAFORM_COLOR:=161} TERRAFORM_CHAR=${POWERLINE_TERRAFORM_CHAR:="❲t❳ "} +KUBERNETES_CONTEXT_THEME_CHAR=${POWERLINE_KUBERNETES_CONTEXT_CHAR:="⎈ "} +KUBERNETES_CONTEXT_THEME_PROMPT_COLOR=${POWERLINE_KUBERNETES_CONTEXT_COLOR:=26} + AWS_PROFILE_CHAR=${POWERLINE_AWS_PROFILE_CHAR:="❲aws❳ "} AWS_PROFILE_PROMPT_COLOR=${POWERLINE_AWS_PROFILE_COLOR:=208}