From ffc1701c0a7f994afd02254709c8d693d21d57b5 Mon Sep 17 00:00:00 2001 From: Ofir Shtrull Date: Thu, 11 Mar 2021 18:25:23 +0200 Subject: [PATCH 1/2] Add to prompt google gcloud active account --- docs/themes-list/powerline-base.rst | 1 + themes/base.theme.bash | 6 ++++++ themes/powerline-multiline/powerline-multiline.theme.bash | 3 +++ themes/powerline-naked/powerline-naked.theme.bash | 3 +++ themes/powerline-plain/powerline-plain.theme.bash | 3 +++ themes/powerline/powerline.base.bash | 7 +++++++ themes/powerline/powerline.theme.bash | 3 +++ 7 files changed, 26 insertions(+) diff --git a/docs/themes-list/powerline-base.rst b/docs/themes-list/powerline-base.rst index d0f6ab30..85ba2388 100644 --- a/docs/themes-list/powerline-base.rst +++ b/docs/themes-list/powerline-base.rst @@ -70,6 +70,7 @@ The contents of the prompt can be "reordered", all the "segments" (every piece o * ``battery`` - Battery information (you'll need to enable the ``battery`` plugin) * ``clock`` - Current time in ``HH:MM:SS`` format * ``cwd`` - Current working directory including full folder hierarchy (c.f. ``wd``\ ) +* ``gcloud`` - Current gcloud active account * ``hostname`` - Host name of machine * ``in_toolbox`` - Show identifier if running inside a `toolbox `_ * ``in_vim`` - Show identifier if running in ``:terminal`` from vim diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 30305957..983aaa73 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -188,6 +188,12 @@ function terraform_workspace_prompt { fi } +function gcloud_account_prompt { + if _command_exists gcloud; then + echo -e "$(gcloud config list account --format "value(core.account)" 2> /dev/null)" + fi +} + function git_prompt_minimal_info { SCM_STATE=${SCM_THEME_PROMPT_CLEAN} diff --git a/themes/powerline-multiline/powerline-multiline.theme.bash b/themes/powerline-multiline/powerline-multiline.theme.bash index a86eac3c..a1663e6f 100644 --- a/themes/powerline-multiline/powerline-multiline.theme.bash +++ b/themes/powerline-multiline/powerline-multiline.theme.bash @@ -91,6 +91,9 @@ HISTORY_NUMBER_THEME_PROMPT_CHAR=${POWERLINE_HISTORY_NUMBER_CHAR:="#"} COMMAND_NUMBER_THEME_PROMPT_COLOR=${POWERLINE_COMMAND_NUMBER_COLOR:=0} COMMAND_NUMBER_THEME_PROMPT_CHAR=${POWERLINE_COMMAND_NUMBER_CHAR:="#"} +GCLOUD_THEME_PROMPT_COLOR=${POWERLINE_GCLOUD_COLOR:=161} +GCLOUD_CHAR=${POWERLINE_GCLOUD_CHAR:="❲G❳ "} + POWERLINE_LEFT_PROMPT=${POWERLINE_LEFT_PROMPT:="scm python_venv ruby node cwd"} POWERLINE_RIGHT_PROMPT=${POWERLINE_RIGHT_PROMPT:="in_vim clock battery user_info"} diff --git a/themes/powerline-naked/powerline-naked.theme.bash b/themes/powerline-naked/powerline-naked.theme.bash index 7a5bd4ed..417ae71a 100644 --- a/themes/powerline-naked/powerline-naked.theme.bash +++ b/themes/powerline-naked/powerline-naked.theme.bash @@ -86,6 +86,9 @@ HISTORY_NUMBER_THEME_PROMPT_CHAR=${POWERLINE_HISTORY_NUMBER_CHAR:="#"} COMMAND_NUMBER_THEME_PROMPT_COLOR=${POWERLINE_COMMAND_NUMBER_COLOR:=254} COMMAND_NUMBER_THEME_PROMPT_CHAR=${POWERLINE_COMMAND_NUMBER_CHAR:="#"} +GCLOUD_THEME_PROMPT_COLOR=${POWERLINE_GCLOUD_COLOR:=161} +GCLOUD_CHAR=${POWERLINE_GCLOUD_CHAR:="❲G❳ "} + POWERLINE_PROMPT=${POWERLINE_PROMPT:="user_info scm python_venv ruby node cwd"} safe_append_prompt_command __powerline_prompt_command diff --git a/themes/powerline-plain/powerline-plain.theme.bash b/themes/powerline-plain/powerline-plain.theme.bash index b2a290a5..0b8f4f56 100644 --- a/themes/powerline-plain/powerline-plain.theme.bash +++ b/themes/powerline-plain/powerline-plain.theme.bash @@ -83,6 +83,9 @@ HISTORY_NUMBER_THEME_PROMPT_CHAR=${POWERLINE_HISTORY_NUMBER_CHAR:="#"} COMMAND_NUMBER_THEME_PROMPT_COLOR=${POWERLINE_COMMAND_NUMBER_COLOR:=0} COMMAND_NUMBER_THEME_PROMPT_CHAR=${POWERLINE_COMMAND_NUMBER_CHAR:="#"} +GCLOUD_THEME_PROMPT_COLOR=${POWERLINE_GCLOUD_COLOR:=161} +GCLOUD_CHAR=${POWERLINE_GCLOUD_CHAR:="❲G❳ "} + POWERLINE_PROMPT=${POWERLINE_PROMPT:="user_info scm python_venv ruby node cwd"} safe_append_prompt_command __powerline_prompt_command diff --git a/themes/powerline/powerline.base.bash b/themes/powerline/powerline.base.bash index dd39337e..43ee8be1 100644 --- a/themes/powerline/powerline.base.bash +++ b/themes/powerline/powerline.base.bash @@ -49,6 +49,13 @@ function __powerline_terraform_prompt() { fi } +function __powerline_gcloud_prompt() { + local active_gcloud_account="" + + active_gcloud_account="$(active_gcloud_account_prompt)" + [[ -n "${active_gcloud_account}" ]] && echo "${GCLOUD_CHAR}${active_gcloud_account}|${GCLOUD_THEME_PROMPT_COLOR}" +} + function __powerline_node_prompt() { local node_version="" diff --git a/themes/powerline/powerline.theme.bash b/themes/powerline/powerline.theme.bash index 3239b360..794121b8 100644 --- a/themes/powerline/powerline.theme.bash +++ b/themes/powerline/powerline.theme.bash @@ -88,6 +88,9 @@ HISTORY_NUMBER_THEME_PROMPT_CHAR=${POWERLINE_HISTORY_NUMBER_CHAR:="#"} COMMAND_NUMBER_THEME_PROMPT_COLOR=${POWERLINE_COMMAND_NUMBER_COLOR:=0} COMMAND_NUMBER_THEME_PROMPT_CHAR=${POWERLINE_COMMAND_NUMBER_CHAR:="#"} +GCLOUD_THEME_PROMPT_COLOR=${POWERLINE_GCLOUD_COLOR:=161} +GCLOUD_CHAR=${POWERLINE_GCLOUD_CHAR:="❲G❳ "} + POWERLINE_PROMPT=${POWERLINE_PROMPT:="user_info scm python_venv ruby node cwd"} safe_append_prompt_command __powerline_prompt_command From 8ae2b1e73df17d72e57608913c4181c963293d8f Mon Sep 17 00:00:00 2001 From: Ofir Shtrull Date: Thu, 11 Mar 2021 18:32:10 +0200 Subject: [PATCH 2/2] fix typo --- themes/base.theme.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 983aaa73..e84cc291 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -188,7 +188,7 @@ function terraform_workspace_prompt { fi } -function gcloud_account_prompt { +function active_gcloud_account_prompt { if _command_exists gcloud; then echo -e "$(gcloud config list account --format "value(core.account)" 2> /dev/null)" fi