-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkubectx.tmux
executable file
·37 lines (31 loc) · 1.22 KB
/
kubectx.tmux
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $CURRENT_DIR/scripts/utils/tmux.sh
# Create map placeholders to handle scripts
# to provide one handler for multiple placeholders.
# Use '//' as separator, due to unix limitation in filenames
placeholders_to_scripts=(
"$kubectx_full//#($CURRENT_DIR/scripts/all.sh)"
"$kubectx_context//#($CURRENT_DIR/scripts/context.sh)"
"$kubectx_cluster//#($CURRENT_DIR/scripts/cluster.sh)"
"$kubectx_namespace//#($CURRENT_DIR/scripts/namespace.sh)"
"$kubectx_user//#($CURRENT_DIR/scripts/user.sh)")
do_interpolation() {
local interpolated=$1
for assignment in ${placeholders_to_scripts[@]}; do
# ${assignment%\/\/*} - remove from // til EOL
# ${assignment#*\/\/} - remove from BOL til //
# ${interpolated//A/B} - replace all occurrences of A in interpolated with B
local interpolated=${interpolated//${assignment%\/\/*}/${assignment#*\/\/}}
done
echo "$interpolated"
}
main() {
local option option_value new_option_value
for option in "status-right" "status-left" "pane-border-format"; do
option_value=$(get_tmux_option "$option")
new_option_value=$(do_interpolation "$option_value")
set_tmux_option "$option" "$new_option_value"
done;
}
main