Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for active gcloud account in powerline prompt #1851

Merged
merged 2 commits into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/themes-list/powerline-base.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/containers/toolbox>`_
* ``in_vim`` - Show identifier if running in ``:terminal`` from vim
Expand Down
6 changes: 6 additions & 0 deletions themes/base.theme.bash
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ function terraform_workspace_prompt {
fi
}

function active_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}

Expand Down
3 changes: 3 additions & 0 deletions themes/powerline-multiline/powerline-multiline.theme.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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"}

Expand Down
3 changes: 3 additions & 0 deletions themes/powerline-naked/powerline-naked.theme.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions themes/powerline-plain/powerline-plain.theme.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions themes/powerline/powerline.base.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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=""

Expand Down
3 changes: 3 additions & 0 deletions themes/powerline/powerline.theme.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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