Skip to content

Commit

Permalink
Merge pull request #1851 from ofirshtrull/master
Browse files Browse the repository at this point in the history
Add support for active gcloud account in powerline prompt
  • Loading branch information
Noah Gorny authored Mar 15, 2021
2 parents c8ef6c9 + 8ae2b1e commit 6f02b8d
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 0 deletions.
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

0 comments on commit 6f02b8d

Please sign in to comment.