Skip to content

Commit 3d2c3bb

Browse files
committed
Merge branch 'master' of https://github.com/bash-it/bash-it into ira/autosave-history-plml
* 'master' of https://github.com/bash-it/bash-it: feat: add k8s namespace indicator (#1887) Add command duration to the powerline theme family
2 parents 10713d5 + 2444a57 commit 3d2c3bb

File tree

7 files changed

+37
-0
lines changed

7 files changed

+37
-0
lines changed

docs/themes-list/powerline-base.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,13 @@ The contents of the prompt can be "reordered", all the "segments" (every piece o
7070
* ``battery`` - Battery information (you'll need to enable the ``battery`` plugin)
7171
* ``clock`` - Current time in ``HH:MM:SS`` format
7272
* ``cwd`` - Current working directory including full folder hierarchy (c.f. ``wd``\ )
73+
* ``duration`` - Duration of the last command. See :ref:`Command duration <command_duration>` for details.
7374
* ``gcloud`` - Current gcloud active account
7475
* ``hostname`` - Host name of machine
7576
* ``in_toolbox`` - Show identifier if running inside a `toolbox <https://github.com/containers/toolbox>`_
7677
* ``in_vim`` - Show identifier if running in ``:terminal`` from vim
7778
* ``k8s_context`` - Show current kubernetes context
79+
* ``k8s_namespace`` - Show current kubernetes namespace
7880
* ``last_status`` - Exit status of last run command
7981
* ``python_venv`` - Python virtual environment information (\ ``virtualenv``\ , ``venv``
8082
and ``conda`` supported)

themes/base.theme.bash

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,10 @@ function k8s_context_prompt {
437437
echo -e "$(kubectl config current-context 2> /dev/null)"
438438
}
439439

440+
function k8s_namespace_prompt {
441+
echo -e "$(kubectl config view --minify --output 'jsonpath={..namespace}' 2> /dev/null)"
442+
}
443+
440444
function virtualenv_prompt {
441445
if [[ -n "$VIRTUAL_ENV" ]]; then
442446
virtualenv=$(basename "$VIRTUAL_ENV")

themes/powerline-multiline/powerline-multiline.theme.bash

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ TERRAFORM_CHAR=${POWERLINE_TERRAFORM_CHAR:="❲t❳ "}
5555
KUBERNETES_CONTEXT_THEME_CHAR=${POWERLINE_KUBERNETES_CONTEXT_CHAR:=""}
5656
KUBERNETES_CONTEXT_THEME_PROMPT_COLOR=${POWERLINE_KUBERNETES_CONTEXT_COLOR:=26}
5757

58+
KUBERNETES_NAMESPACE_THEME_CHAR=${POWERLINE_KUBERNETES_NAMESPACE_CHAR:=""}
59+
KUBERNETES_NAMESPACE_THEME_PROMPT_COLOR=${POWERLINE_KUBERNETES_NAMESPACE_COLOR:=64}
60+
5861
AWS_PROFILE_CHAR=${POWERLINE_AWS_PROFILE_CHAR:="❲aws❳ "}
5962
AWS_PROFILE_PROMPT_COLOR=${POWERLINE_AWS_PROFILE_COLOR:=208}
6063

@@ -94,6 +97,8 @@ COMMAND_NUMBER_THEME_PROMPT_CHAR=${POWERLINE_COMMAND_NUMBER_CHAR:="#"}
9497
GCLOUD_THEME_PROMPT_COLOR=${POWERLINE_GCLOUD_COLOR:=161}
9598
GCLOUD_CHAR=${POWERLINE_GCLOUD_CHAR:="❲G❳ "}
9699

100+
COMMAND_DURATION_PROMPT_COLOR=${POWERLINE_COMMAND_DURATION_COLOR:=129}
101+
97102
POWERLINE_LEFT_PROMPT=${POWERLINE_LEFT_PROMPT:="scm python_venv ruby node cwd"}
98103
POWERLINE_RIGHT_PROMPT=${POWERLINE_RIGHT_PROMPT:="in_vim clock battery user_info"}
99104

themes/powerline-naked/powerline-naked.theme.bash

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ TERRAFORM_CHAR=${POWERLINE_TERRAFORM_CHAR:="❲t❳ "}
5050
KUBERNETES_CONTEXT_THEME_CHAR=${POWERLINE_KUBERNETES_CONTEXT_CHAR:=""}
5151
KUBERNETES_CONTEXT_THEME_PROMPT_COLOR=${POWERLINE_KUBERNETES_CONTEXT_COLOR:=26}
5252

53+
KUBERNETES_NAMESPACE_THEME_CHAR=${POWERLINE_KUBERNETES_NAMESPACE_CHAR:=""}
54+
KUBERNETES_NAMESPACE_THEME_PROMPT_COLOR=${POWERLINE_KUBERNETES_NAMESPACE_COLOR:=64}
55+
5356
AWS_PROFILE_CHAR=${POWERLINE_AWS_PROFILE_CHAR:="❲aws❳ "}
5457
AWS_PROFILE_PROMPT_COLOR=${POWERLINE_AWS_PROFILE_COLOR:=208}
5558

themes/powerline-plain/powerline-plain.theme.bash

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ TERRAFORM_CHAR=${POWERLINE_TERRAFORM_CHAR:="❲t❳ "}
4747
KUBERNETES_CONTEXT_THEME_CHAR=${POWERLINE_KUBERNETES_CONTEXT_CHAR:=""}
4848
KUBERNETES_CONTEXT_THEME_PROMPT_COLOR=${POWERLINE_KUBERNETES_CONTEXT_COLOR:=26}
4949

50+
KUBERNETES_NAMESPACE_THEME_CHAR=${POWERLINE_KUBERNETES_NAMESPACE_CHAR:=""}
51+
KUBERNETES_NAMESPACE_THEME_PROMPT_COLOR=${POWERLINE_KUBERNETES_NAMESPACE_COLOR:=60}
52+
5053
AWS_PROFILE_CHAR=${POWERLINE_AWS_PROFILE_CHAR:="❲aws❳ "}
5154
AWS_PROFILE_PROMPT_COLOR=${POWERLINE_AWS_PROFILE_COLOR:=208}
5255

themes/powerline/powerline.base.bash

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ function __powerline_k8s_context_prompt() {
8585
[[ -n "${kubernetes_context}" ]] && echo "${KUBERNETES_CONTEXT_THEME_CHAR}${kubernetes_context}|${KUBERNETES_CONTEXT_THEME_PROMPT_COLOR}"
8686
}
8787

88+
function __powerline_k8s_namespace_prompt() {
89+
local kubernetes_namespace=""
90+
91+
if _command_exists kubectl; then
92+
kubernetes_namespace="$(k8s_namespace_prompt)"
93+
fi
94+
95+
[[ -n "${kubernetes_namespace}" ]] && echo "${KUBERNETES_NAMESPACE_THEME_CHAR}${kubernetes_namespace}|${KUBERNETES_NAMESPACE_THEME_PROMPT_COLOR}"
96+
}
97+
8898
function __powerline_python_venv_prompt() {
8999
set +u
90100
local python_venv=""
@@ -210,6 +220,11 @@ function __powerline_command_number_prompt() {
210220
echo "${COMMAND_NUMBER_THEME_PROMPT_CHAR}\#|${COMMAND_NUMBER_THEME_PROMPT_COLOR}"
211221
}
212222

223+
function __powerline_duration_prompt() {
224+
local duration=$(_command_duration)
225+
[[ -n "$duration" ]] && echo "${duration}|${COMMAND_DURATION_PROMPT_COLOR}"
226+
}
227+
213228
function __powerline_left_segment() {
214229
local params
215230
IFS="|" read -ra params <<< "${1}"

themes/powerline/powerline.theme.bash

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ TERRAFORM_CHAR=${POWERLINE_TERRAFORM_CHAR:="❲t❳ "}
5252
KUBERNETES_CONTEXT_THEME_CHAR=${POWERLINE_KUBERNETES_CONTEXT_CHAR:=""}
5353
KUBERNETES_CONTEXT_THEME_PROMPT_COLOR=${POWERLINE_KUBERNETES_CONTEXT_COLOR:=26}
5454

55+
KUBERNETES_NAMESPACE_THEME_CHAR=${POWERLINE_KUBERNETES_NAMESPACE_CHAR:=""}
56+
KUBERNETES_NAMESPACE_THEME_PROMPT_COLOR=${POWERLINE_KUBERNETES_NAMESPACE_COLOR:=64}
57+
5558
AWS_PROFILE_CHAR=${POWERLINE_AWS_PROFILE_CHAR:="❲aws❳ "}
5659
AWS_PROFILE_PROMPT_COLOR=${POWERLINE_AWS_PROFILE_COLOR:=208}
5760

@@ -91,6 +94,8 @@ COMMAND_NUMBER_THEME_PROMPT_CHAR=${POWERLINE_COMMAND_NUMBER_CHAR:="#"}
9194
GCLOUD_THEME_PROMPT_COLOR=${POWERLINE_GCLOUD_COLOR:=161}
9295
GCLOUD_CHAR=${POWERLINE_GCLOUD_CHAR:="❲G❳ "}
9396

97+
COMMAND_DURATION_PROMPT_COLOR=${POWERLINE_COMMAND_DURATION_COLOR:=129}
98+
9499
POWERLINE_PROMPT=${POWERLINE_PROMPT:="user_info scm python_venv ruby node cwd"}
95100

96101
safe_append_prompt_command __powerline_prompt_command

0 commit comments

Comments
 (0)