mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-04-10 16:32:00 +00:00
Compare commits
17 Commits
365e67d61c
...
ef58ded45b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ef58ded45b | ||
|
|
7c10d9839f | ||
|
|
103246c198 | ||
|
|
8a6e4ee0bf | ||
|
|
9682a8a680 | ||
|
|
ec3e684941 | ||
|
|
a80dc8a510 | ||
|
|
c32dc46b03 | ||
|
|
f66a13f88c | ||
|
|
9ff3be7dad | ||
|
|
1aa896ebe3 | ||
|
|
d6bce941ee | ||
|
|
8c35cc24d6 | ||
|
|
d6faa296d9 | ||
|
|
e373869348 | ||
|
|
375293f612 | ||
|
|
259ee26071 |
@@ -127,6 +127,10 @@ The default prompt layout is:
|
|||||||
```sh
|
```sh
|
||||||
(<symbol>|<context>:<namespace>)
|
(<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:
|
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_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 |
|
| `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:
|
To disable a feature, set it to an empty string:
|
||||||
|
|
||||||
```sh
|
```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
|
as possible. Red was chosen as the context name to stand out, and cyan for the
|
||||||
namespace.
|
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
|
Set the variable to an empty string if you do not want color for each
|
||||||
prompt section:
|
prompt section:
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,28 @@ KUBE_PS1_SUFFIX="${KUBE_PS1_SUFFIX-)}"
|
|||||||
|
|
||||||
KUBE_PS1_HIDE_IF_NOCONTEXT="${KUBE_PS1_HIDE_IF_NOCONTEXT:-false}"
|
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_KUBECONFIG_CACHE="${KUBECONFIG}"
|
||||||
_KUBE_PS1_DISABLE_PATH="${HOME}/.kube/kube-ps1/disabled"
|
_KUBE_PS1_DISABLE_PATH="${HOME}/.kube/kube-ps1/disabled"
|
||||||
_KUBE_PS1_LAST_TIME=0
|
_KUBE_PS1_LAST_TIME=0
|
||||||
@@ -165,7 +187,7 @@ _kube_ps1_symbol() {
|
|||||||
|
|
||||||
local symbol=""
|
local symbol=""
|
||||||
local symbol_default=$'\u2388'
|
local symbol_default=$'\u2388'
|
||||||
local symbol_img="☸️"
|
local symbol_img="☸️"
|
||||||
local k8s_glyph=$'\Uf10fe'
|
local k8s_glyph=$'\Uf10fe'
|
||||||
local k8s_symbol_color=blue
|
local k8s_symbol_color=blue
|
||||||
local oc_glyph=$'\ue7b7'
|
local oc_glyph=$'\ue7b7'
|
||||||
@@ -326,6 +348,35 @@ _kube_ps1_get_context_ns() {
|
|||||||
_kube_ps1_get_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
|
# Set kube-ps1 shell defaults
|
||||||
_kube_ps1_init
|
_kube_ps1_init
|
||||||
|
|
||||||
@@ -402,6 +453,11 @@ kube_ps1() {
|
|||||||
# Background Color
|
# Background Color
|
||||||
[[ -n "${KUBE_PS1_BG_COLOR}" ]] && KUBE_PS1+="$(_kube_ps1_color_bg "${KUBE_PS1_BG_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
|
# Prefix
|
||||||
if [[ -z "${KUBE_PS1_PREFIX_COLOR:-}" ]] && [[ -n "${KUBE_PS1_PREFIX}" ]]; then
|
if [[ -z "${KUBE_PS1_PREFIX_COLOR:-}" ]] && [[ -n "${KUBE_PS1_PREFIX}" ]]; then
|
||||||
KUBE_PS1+="${KUBE_PS1_PREFIX}"
|
KUBE_PS1+="${KUBE_PS1_PREFIX}"
|
||||||
|
|||||||
@@ -30,14 +30,20 @@ function tofu_version_prompt_info() {
|
|||||||
alias tt='tofu'
|
alias tt='tofu'
|
||||||
alias tta='tofu apply'
|
alias tta='tofu apply'
|
||||||
alias tta!='tofu apply -auto-approve'
|
alias tta!='tofu apply -auto-approve'
|
||||||
|
alias ttap='tofu apply -parallelism=1'
|
||||||
|
alias ttapp='tofu apply tfplan'
|
||||||
alias ttc='tofu console'
|
alias ttc='tofu console'
|
||||||
alias ttd='tofu destroy'
|
alias ttd='tofu destroy'
|
||||||
alias ttd!='tofu destroy -auto-approve'
|
alias ttd!='tofu destroy -auto-approve'
|
||||||
alias ttf='tofu fmt'
|
alias ttf='tofu fmt'
|
||||||
alias ttfr='tofu fmt -recursive'
|
alias ttfr='tofu fmt -recursive'
|
||||||
alias tti='tofu init'
|
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 tto='tofu output'
|
||||||
alias ttp='tofu plan'
|
alias ttp='tofu plan'
|
||||||
|
alias ttpo='tofu plan -out tfplan'
|
||||||
alias ttv='tofu validate'
|
alias ttv='tofu validate'
|
||||||
alias tts='tofu state'
|
alias tts='tofu state'
|
||||||
alias ttsh='tofu show'
|
alias ttsh='tofu show'
|
||||||
|
|||||||
@@ -4,21 +4,21 @@ function tf_prompt_info() {
|
|||||||
# check if in terraform dir and file exists
|
# check if in terraform dir and file exists
|
||||||
[[ -d "${TF_DATA_DIR:-.terraform}" && -r "${TF_DATA_DIR:-.terraform}/environment" ]] || return
|
[[ -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-]}"
|
echo "${ZSH_THEME_TF_PROMPT_PREFIX-[}${workspace:gs/%/%%}${ZSH_THEME_TF_PROMPT_SUFFIX-]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function tf_version_prompt_info() {
|
function tf_version_prompt_info() {
|
||||||
local terraform_version
|
local terraform_version
|
||||||
terraform_version=$(terraform --version | head -n 1 | cut -d ' ' -f 2)
|
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-]}"
|
echo "${ZSH_THEME_TF_VERSION_PROMPT_PREFIX-[}${terraform_version:gs/%/%%}${ZSH_THEME_TF_VERSION_PROMPT_SUFFIX-]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
alias tf='terraform'
|
alias tf='terraform'
|
||||||
alias tfa='terraform apply'
|
alias tfa='terraform apply'
|
||||||
alias tfa!='terraform apply -auto-approve'
|
alias tfa!='terraform apply -auto-approve'
|
||||||
alias tfap='terraform apply -parallelism=1'
|
alias tfap='terraform apply -parallelism=1'
|
||||||
|
alias tfapp='terraform apply tfplan'
|
||||||
alias tfc='terraform console'
|
alias tfc='terraform console'
|
||||||
alias tfd='terraform destroy'
|
alias tfd='terraform destroy'
|
||||||
alias tfd!='terraform destroy -auto-approve'
|
alias tfd!='terraform destroy -auto-approve'
|
||||||
@@ -31,6 +31,7 @@ alias tfiu='terraform init -upgrade'
|
|||||||
alias tfiur='terraform init -upgrade -reconfigure'
|
alias tfiur='terraform init -upgrade -reconfigure'
|
||||||
alias tfo='terraform output'
|
alias tfo='terraform output'
|
||||||
alias tfp='terraform plan'
|
alias tfp='terraform plan'
|
||||||
|
alias tfpo='terraform plan -out tfplan'
|
||||||
alias tfv='terraform validate'
|
alias tfv='terraform validate'
|
||||||
alias tfs='terraform state'
|
alias tfs='terraform state'
|
||||||
alias tft='terraform test'
|
alias tft='terraform test'
|
||||||
|
|||||||
Reference in New Issue
Block a user