Skip to content

Commit aa14996

Browse files
Merge pull request dracula#152 from JannoTjarks/kubernetes-context
Added kubernetes-context plugin
2 parents 79521cc + 1809c14 commit aa14996

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Configuration and options can be found at [draculatheme.com/tmux](https://dracul
2929
- When prefix is enabled smiley face turns from green to yellow
3030
- When charging, 'AC' is displayed
3131
- If forecast information is available, a ☀, ☁, ☂, or ❄ unicode character corresponding with the forecast is displayed alongside the temperature
32+
- Current kubernetes context
3233

3334
## Compatibility
3435

scripts/dracula.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ main()
2424
show_border_contrast=$(get_tmux_option "@dracula-border-contrast" false)
2525
show_day_month=$(get_tmux_option "@dracula-day-month" false)
2626
show_refresh=$(get_tmux_option "@dracula-refresh-rate" 5)
27+
show_kubernetes_context_label=$(get_tmux_option "@dracula-kubernetes-context-label" "")
2728
IFS=' ' read -r -a plugins <<< $(get_tmux_option "@dracula-plugins" "battery network weather")
2829

2930
# Dracula Color Pallette
@@ -168,6 +169,11 @@ main()
168169
script="#($current_dir/network_ping.sh)"
169170
fi
170171

172+
if [ $plugin = "kubernetes-context" ]; then
173+
IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-kubernetes-context-colors" "cyan dark_gray")
174+
script="#($current_dir/kubernetes_context.sh $show_kubernetes_context_label)"
175+
fi
176+
171177
if [ $plugin = "weather" ]; then
172178
# wait unit $datafile exists just to avoid errors
173179
# this should almost never need to wait unless something unexpected occurs

scripts/kubernetes_context.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
# setting the locale, some users have issues with different locales, this forces the correct one
3+
export LC_ALL=en_US.UTF-8
4+
5+
label=$1
6+
7+
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
8+
source $current_dir/utils.sh
9+
10+
current_context=$(kubectl config view --minify --output 'jsonpath={.current-context}'; echo)
11+
current_user=$(kubectl config view --minify --output 'jsonpath={.contexts[?(@.name=="'$current_context'")].context.user}'; echo)
12+
current_cluster=$(kubectl config view --minify --output 'jsonpath={.contexts[?(@.name=="'$current_context'")].context.cluster}'; echo)
13+
current_namespace=$(kubectl config view --minify --output 'jsonpath={.contexts[?(@.name=="'$current_context'")].context.namespace}'; echo)
14+
15+
main()
16+
{
17+
# storing the refresh rate in the variable RATE, default is 5
18+
RATE=$(get_tmux_option "@dracula-refresh-rate" 5)
19+
OUTPUT_STRING=""
20+
if [ ! -z "$current_user" ]
21+
then
22+
OUTPUT_STRING="${current_user}@"
23+
fi
24+
25+
if [ ! -z "$current_cluster" ]
26+
then
27+
OUTPUT_STRING="${OUTPUT_STRING}${current_cluster}"
28+
fi
29+
30+
if [ ! -z "$current_namespace" ]
31+
then
32+
OUTPUT_STRING="${OUTPUT_STRING}:${current_namespace}"
33+
fi
34+
35+
if [ "$OUTPUT_STRING" = "" ]
36+
then
37+
OUTPUT_STRING="kubeconfig not valid"
38+
fi
39+
40+
if [ "$label" = "" ]
41+
then
42+
echo "${OUTPUT_STRING}"
43+
else
44+
echo "${label} ${OUTPUT_STRING}"
45+
fi
46+
47+
sleep $RATE
48+
}
49+
50+
# run the main driver
51+
main

0 commit comments

Comments
 (0)