1
0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2026-04-10 16:32:00 +00:00

Compare commits

...

17 Commits

Author SHA1 Message Date
Oleksandr Molchanov
ef58ded45b Merge 8a6e4ee0bf into 7c10d9839f 2026-04-08 08:28:43 +00:00
Chris Schindlbeck
7c10d9839f feat(terraform): add aliases for terraform: tfapp, tfpo 2026-04-07 12:25:32 +02:00
Chris Schindlbeck
103246c198 feat(opentofu): add aliases for opentofu: ttap, ttapp, ttir, ttiu, ttiur, ttpo 2026-04-07 12:25:32 +02:00
Oleksandr Molchanov
8a6e4ee0bf docs: remove extra spaces 2026-03-14 16:19:00 +02:00
Oleksandr Molchanov
9682a8a680 fix: a bug with custom padding 2026-03-14 16:15:18 +02:00
Oleksandr Molchanov
ec3e684941 fix: extend dev regex 2026-03-14 14:08:04 +02:00
Oleksandr Molchanov
a80dc8a510 docs: improve wording 2026-03-14 10:30:19 +02:00
Oleksandr Molchanov
c32dc46b03 docs: rename KUBE variables to KUBE_PS1 to inherit plugin convention 2026-03-13 23:58:52 +02:00
Oleksandr Molchanov
f66a13f88c style: rename KUBE variables to KUBE_PS1 to inherit plugin convention 2026-03-13 23:30:11 +02:00
Oleksandr Molchanov
9ff3be7dad fix: correct variable names 2026-03-13 21:18:43 +02:00
Oleksandr Molchanov
1aa896ebe3 chore: rename gloabal variables 2026-03-13 21:16:15 +02:00
Oleksandr Molchanov
d6bce941ee docs: update README.md 2026-03-13 21:10:00 +02:00
Oleksandr Molchanov
8c35cc24d6 docs: update README.md 2026-03-13 21:06:53 +02:00
Oleksandr Molchanov
d6faa296d9 docs: update README.md 2026-03-13 21:05:27 +02:00
Oleksandr Molchanov
e373869348 chore: remove new line at the EOF 2026-03-13 20:50:21 +02:00
Oleksandr Molchanov
375293f612 chore: add missing quotes 2026-03-13 20:49:02 +02:00
Oleksandr Molchanov
259ee26071 feat(kube-ps1): add environment indicator to the prompt layout 2026-03-13 20:27:33 +02:00
4 changed files with 99 additions and 6 deletions

View File

@@ -127,6 +127,10 @@ The default prompt layout is:
```sh
(<symbol>|<context>:<namespace>)
```
You can enable kube environment context (like dev/staging/test/prod) via `KUBE_PS1_ENV_CTX_ENABLE=true`. In this case, the layout will be:
```sh
[<kube-environment>] (<symbol>|<context>:<namespace>)
```
If the current-context is not set, kube-ps1 will return the following:
@@ -204,6 +208,23 @@ the following variables:
| `KUBE_PS1_CTX_COLOR_FUNCTION` | No default, must be user supplied | Function to customize context color based on context name |
| `KUBE_PS1_HIDE_IF_NOCONTEXT` | `false` | Hide the kube-ps1 prompt if no context is set |
For more control over the Kubernetes environment context, you can adjust:
| Variable | Default | Meaning |
| :------- | :-----: | ------- |
| `KUBE_PS1_ENV_CTX_ENABLE` | `false` | Extract environment identifiers from context and display them as a separate block in square brackets, e.g `testing-mycluster` becomes `[test] mycluster` |
| `KUBE_PS1_ENV_PADDING` | one space | Padding (spaces or characters) added around the environment block |
| `KUBE_PS1_ENV_OPEN_SYMBOL` | `[` | Opening symbol used for the environment block |
| `KUBE_PS1_ENV_CLOSE_SYMBOL` | `]` | Closing symbol used for the environment block |
| `KUBE_PS1_ENV_PROD_LABEL` | `prod` | Set default production label |
| `KUBE_PS1_ENV_STG_LABEL` | `stag` | Set default staging label |
| `KUBE_PS1_ENV_TEST_LABEL` | `test` | Set default testing label |
| `KUBE_PS1_ENV_DEV_LABEL` | `dev` | Set default developing label |
| `KUBE_PS1_ENV_PROD_RE` | `(production\|prod)-` | Regex used to detect production in the context name |
| `KUBE_PS1_ENV_STG_RE` | `(staging\|stg)-` | Regex used to detect staging in the context name |
| `KUBE_PS1_ENV_TEST_RE` | `(testing\|test)-` | Regex used to detect test in the context name |
| `KUBE_PS1_ENV_DEV_RE` | `dev(elop(ment)?)?-` | Regex used to detect development in the context name |
To disable a feature, set it to an empty string:
```sh
@@ -227,6 +248,15 @@ Blue was used for the default symbol to match the Kubernetes color as closely
as possible. Red was chosen as the context name to stand out, and cyan for the
namespace.
If `KUBE_PS1_ENV_CTX_ENABLE` is set to `true`, you can also modify:
| Variable | Default | Meaning |
| :------- | :-----: | ------- |
| `KUBE_PS1_ENV_PROD_COLOR` | `red` | Set default color of the production environment |
| `KUBE_PS1_ENV_STG_COLOR` | `yellow` | Set default color of the staging environment |
| `KUBE_PS1_ENV_TEST_COLOR` | `green` | Set default color of the testing environment |
| `KUBE_PS1_ENV_DEV_COLOR` | `blue` | Set default color of the development environment |
Set the variable to an empty string if you do not want color for each
prompt section:

View File

@@ -36,6 +36,28 @@ KUBE_PS1_SUFFIX="${KUBE_PS1_SUFFIX-)}"
KUBE_PS1_HIDE_IF_NOCONTEXT="${KUBE_PS1_HIDE_IF_NOCONTEXT:-false}"
# Kube environment variables
KUBE_PS1_ENV_CTX_ENABLE="${KUBE_PS1_ENV_CTX_ENABLE:-false}"
KUBE_PS1_ENV_PADDING="${KUBE_PS1_ENV_PADDING:- }"
KUBE_PS1_ENV_OPEN_SYMBOL="${KUBE_PS1_ENV_OPEN_SYMBOL:-[}"
KUBE_PS1_ENV_CLOSE_SYMBOL="${KUBE_PS1_ENV_CLOSE_SYMBOL:-]}"
KUBE_PS1_ENV_PROD_COLOR="${KUBE_PS1_ENV_PROD_COLOR:-red}"
KUBE_PS1_ENV_STG_COLOR="${KUBE_PS1_ENV_STG_COLOR:-yellow}"
KUBE_PS1_ENV_TEST_COLOR="${KUBE_PS1_ENV_TEST_COLOR:-green}"
KUBE_PS1_ENV_DEV_COLOR="${KUBE_PS1_ENV_DEV_COLOR:-blue}"
KUBE_PS1_ENV_PROD_LABEL="${KUBE_PS1_ENV_PROD_LABEL:-prod}"
KUBE_PS1_ENV_STG_LABEL="${KUBE_PS1_ENV_STG_LABEL:-stag}"
KUBE_PS1_ENV_TEST_LABEL="${KUBE_PS1_ENV_TEST_LABEL:-test}"
KUBE_PS1_ENV_DEV_LABEL="${KUBE_PS1_ENV_DEV_LABEL:-dev}"
KUBE_PS1_ENV_PROD_RE="${KUBE_PS1_ENV_PROD_RE:-(production|prod)-}"
KUBE_PS1_ENV_STG_RE="${KUBE_PS1_ENV_STG_RE:-(staging|stg)-}"
KUBE_PS1_ENV_TEST_RE="${KUBE_PS1_ENV_TEST_RE:-(testing|test)-}"
KUBE_PS1_ENV_DEV_RE="${KUBE_PS1_ENV_DEV_RE:-dev(elop(ment)?)?-}"
_KUBE_PS1_KUBECONFIG_CACHE="${KUBECONFIG}"
_KUBE_PS1_DISABLE_PATH="${HOME}/.kube/kube-ps1/disabled"
_KUBE_PS1_LAST_TIME=0
@@ -165,7 +187,7 @@ _kube_ps1_symbol() {
local symbol=""
local symbol_default=$'\u2388'
local symbol_img="☸️"
local symbol_img="☸️"
local k8s_glyph=$'\Uf10fe'
local k8s_symbol_color=blue
local oc_glyph=$'\ue7b7'
@@ -326,6 +348,35 @@ _kube_ps1_get_context_ns() {
_kube_ps1_get_ns
}
_kube_ps1_cut_context() {
local pattern="$1"
KUBE_PS1_CONTEXT="$(sed -E "s/${pattern}//g" <<< "${KUBE_PS1_CONTEXT}")"
}
_kube_ps1_set_env_ctx() {
local ctx_color env_label
if grep -qE "${KUBE_PS1_ENV_PROD_RE}" <<< "${KUBE_PS1_CONTEXT}"; then
_kube_ps1_cut_context "${KUBE_PS1_ENV_PROD_RE}"
ctx_color="$(_kube_ps1_color_fg "${KUBE_PS1_ENV_PROD_COLOR}")"
env_label="${KUBE_PS1_ENV_PROD_LABEL}"
elif grep -qE "${KUBE_PS1_ENV_STG_RE}" <<< "${KUBE_PS1_CONTEXT}"; then
_kube_ps1_cut_context "${KUBE_PS1_ENV_STG_RE}"
ctx_color="$(_kube_ps1_color_fg "${KUBE_PS1_ENV_STG_COLOR}")"
env_label="${KUBE_PS1_ENV_STG_LABEL}"
elif grep -qE "${KUBE_PS1_ENV_TEST_RE}" <<< "${KUBE_PS1_CONTEXT}"; then
_kube_ps1_cut_context "${KUBE_PS1_ENV_TEST_RE}"
ctx_color="$(_kube_ps1_color_fg "${KUBE_PS1_ENV_TEST_COLOR}")"
env_label="${KUBE_PS1_ENV_TEST_LABEL}"
elif grep -qE "${KUBE_PS1_ENV_DEV_RE}" <<< "${KUBE_PS1_CONTEXT}"; then
_kube_ps1_cut_context "${KUBE_PS1_ENV_DEV_RE}"
ctx_color="$(_kube_ps1_color_fg "${KUBE_PS1_ENV_DEV_COLOR}")"
env_label="${KUBE_PS1_ENV_DEV_LABEL}"
fi
KUBE_PS1+="${KUBE_PS1_ENV_PADDING}${KUBE_PS1_ENV_OPEN_SYMBOL}${ctx_color}${env_label}${KUBE_PS1_RESET_COLOR}${KUBE_PS1_ENV_CLOSE_SYMBOL}${KUBE_PS1_ENV_PADDING}"
}
# Set kube-ps1 shell defaults
_kube_ps1_init
@@ -402,6 +453,11 @@ kube_ps1() {
# Background Color
[[ -n "${KUBE_PS1_BG_COLOR}" ]] && KUBE_PS1+="$(_kube_ps1_color_bg "${KUBE_PS1_BG_COLOR}")"
# Context Env
if [[ -n "${KUBE_PS1_ENV_CTX_ENABLE}" ]] && [[ "${KUBE_PS1_ENV_CTX_ENABLE}" == true ]]; then
_kube_ps1_set_env_ctx
fi
# Prefix
if [[ -z "${KUBE_PS1_PREFIX_COLOR:-}" ]] && [[ -n "${KUBE_PS1_PREFIX}" ]]; then
KUBE_PS1+="${KUBE_PS1_PREFIX}"

View File

@@ -30,14 +30,20 @@ function tofu_version_prompt_info() {
alias tt='tofu'
alias tta='tofu apply'
alias tta!='tofu apply -auto-approve'
alias ttap='tofu apply -parallelism=1'
alias ttapp='tofu apply tfplan'
alias ttc='tofu console'
alias ttd='tofu destroy'
alias ttd!='tofu destroy -auto-approve'
alias ttf='tofu fmt'
alias ttfr='tofu fmt -recursive'
alias tti='tofu init'
alias ttir='tofu init -reconfigure'
alias ttiu='tofu init -upgrade'
alias ttiur='tofu init -upgrade -reconfigure'
alias tto='tofu output'
alias ttp='tofu plan'
alias ttpo='tofu plan -out tfplan'
alias ttv='tofu validate'
alias tts='tofu state'
alias ttsh='tofu show'

View File

@@ -4,21 +4,21 @@ function tf_prompt_info() {
# check if in terraform dir and file exists
[[ -d "${TF_DATA_DIR:-.terraform}" && -r "${TF_DATA_DIR:-.terraform}/environment" ]] || return
local workspace="$(< "${TF_DATA_DIR:-.terraform}/environment")"
local workspace="$(<"${TF_DATA_DIR:-.terraform}/environment")"
echo "${ZSH_THEME_TF_PROMPT_PREFIX-[}${workspace:gs/%/%%}${ZSH_THEME_TF_PROMPT_SUFFIX-]}"
}
function tf_version_prompt_info() {
local terraform_version
terraform_version=$(terraform --version | head -n 1 | cut -d ' ' -f 2)
echo "${ZSH_THEME_TF_VERSION_PROMPT_PREFIX-[}${terraform_version:gs/%/%%}${ZSH_THEME_TF_VERSION_PROMPT_SUFFIX-]}"
local terraform_version
terraform_version=$(terraform --version | head -n 1 | cut -d ' ' -f 2)
echo "${ZSH_THEME_TF_VERSION_PROMPT_PREFIX-[}${terraform_version:gs/%/%%}${ZSH_THEME_TF_VERSION_PROMPT_SUFFIX-]}"
}
alias tf='terraform'
alias tfa='terraform apply'
alias tfa!='terraform apply -auto-approve'
alias tfap='terraform apply -parallelism=1'
alias tfapp='terraform apply tfplan'
alias tfc='terraform console'
alias tfd='terraform destroy'
alias tfd!='terraform destroy -auto-approve'
@@ -31,6 +31,7 @@ alias tfiu='terraform init -upgrade'
alias tfiur='terraform init -upgrade -reconfigure'
alias tfo='terraform output'
alias tfp='terraform plan'
alias tfpo='terraform plan -out tfplan'
alias tfv='terraform validate'
alias tfs='terraform state'
alias tft='terraform test'