This commit is contained in:
Jonas Forsberg 2021-11-12 11:36:09 +01:00
parent 2208cb1939
commit 869a492479
No known key found for this signature in database
GPG Key ID: F2E9818C70350CC9
2 changed files with 36 additions and 32 deletions

View File

@ -1,15 +1,5 @@
#!/bin/bash #!/bin/bash
function kc(){
# print all kubernetes contexts
kubectl config get-contexts
}
function kuc(){
# use kubernetes context <param>
kubectl config use-context "$1"
}
function kubernetes_configs(){ function kubernetes_configs(){
# set KUBECONFIG to default kubeconfig and all *.yaml files in .kube # set KUBECONFIG to default kubeconfig and all *.yaml files in .kube
local KUBE_CONFIG_DEFAULT="$HOME/.kube/config" local KUBE_CONFIG_DEFAULT="$HOME/.kube/config"
@ -24,5 +14,20 @@ function kubernetes_configs(){
export KUBECONFIG="$file:$KUBECONFIG" export KUBECONFIG="$file:$KUBECONFIG"
done done
} }
kubernetes_configs kubernetes_configs
function kc(){
# print all kubernetes contexts
kubectl config get-contexts
}
function kuc(){
# use kubernetes context <param>
kubectl config use-context "$1"
}
#bash completion for function kuc
if [[ $(command -v kubectl) ]];then
complete -W "$(kubectl config get-contexts -o name)" kuc
fi

View File

@ -2,37 +2,36 @@
function set_bash_prompt () { function set_bash_prompt () {
local LAST_EXIT_STATUS=$? local LAST_EXIT_STATUS=$?
local EXIT_STATUS="" local EXIT_STATUS=""
local Color_Off='\033[0m' # Text Reset local GIT_BRANCH=""
local PYTHON_ENV=""
local K8S_CURRENT_CONTEXT=""
local COLOR_OFF='\033[0m'
local COLOR_DIVIDER="\033[0;32m" local COLOR_DIVIDER="\033[0;32m"
local COLOR_USERNAME="\[\e[34;1m\]" local COLOR_USERNAME="\[\e[34;1m\]"
local COLOR_USERHOSTAT="\[\e[34;1m\]" local COLOR_USERHOSTAT="\[\e[34;1m\]"
local COLOR_HOSTNAME="\[\e[34;1m\]" local COLOR_HOSTNAME="\[\e[34;1m\]"
local COLOR_GITBRANCH="\[\e[33;1m\]" local COLOR_GITBRANCH="\[\e[33;1m\]"
local COLOR_VENV="\033[0;36m" local COLOR_VENV="\033[0;36m"
local PATH_COLOR="\033[0;37m" local COLOR_PATH="\033[0;37m"
local COLOR_EXIT_STATUS="[\033[1;37m\033[41m"
local COLOR_KUBERNETES="\033[1;37m\033[44m"
if [[ $LAST_EXIT_STATUS != 0 ]];then local CURRENT_CONTEXT=""
EXIT_STATUS="${COLOR_DIVIDER}[\033[1;37m\033[41m${LAST_EXIT_STATUS}${Color_Off}${COLOR_DIVIDER}]"
[[ $LAST_EXIT_STATUS != 0 ]] && EXIT_STATUS="${COLOR_DIVIDER}${COLOR_EXIT_STATUS}${LAST_EXIT_STATUS}${COLOR_DIVIDER}]"
[[ $(type -t __git_ps1) == function ]] && GIT_BRANCH="${COLOR_GITBRANCH}$(__git_ps1)${COLOR_DIVIDER}"
[[ -n "$VIRTUAL_ENV" ]] && PYTHON_ENV="${COLOR_DIVIDER}(${COLOR_VENV}${VIRTUAL_ENV##*/}${COLOR_DIVIDER})"
if [[ $(type kubectl) ]]; then
CURRENT_CONTEXT="$(kubectl config current-context)"
if [[ "$CURRENT_CONTEXT" != "default" ]];then
K8S_CURRENT_CONTEXT="${COLOR_DIVIDER}[${COLOR_KUBERNETES}${CURRENT_CONTEXT}${COLOR_DIVIDER}]"
fi
fi fi
PS1="\n${COLOR_DIVIDER}┌──(${COLOR_USERNAME}\u${COLOR_USERHOSTAT}@${COLOR_HOSTNAME}\h${COLOR_DIVIDER})─[${PATH_COLOR}\w${COLOR_DIVIDER}]${EXIT_STATUS}" PS1="\n${COLOR_DIVIDER}┌──(${COLOR_USERNAME}\u${COLOR_USERHOSTAT}@${COLOR_HOSTNAME}\h${COLOR_DIVIDER})─[${COLOR_PATH}\w${COLOR_DIVIDER}]${EXIT_STATUS}${PYTHON_ENV}${K8S_CURRENT_CONTEXT}${GIT_BRANCH}"
PS1="$PS1${COLOR_GITBRANCH}$(__git_ps1)${COLOR_DIVIDER}" PS1="${PS1}\n${COLOR_DIVIDER}└─\$${COLOR_OFF} "
# # Add git branch portion of the prompt"
# if ! git_loc="$(type -p "$git_command_name")" || [ -z "$git_loc" ]; then
# # Git is installed
# if [ -d .git ] || git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
# # Inside of a git repository
# GIT_BRANCH=$(git symbolic-ref --short HEAD)
# PS1="${PS1}:${COLOR_GITBRANCH}${GIT_BRANCH}${COLOR_DIVIDER}"
# fi
# fi
# Add Python VirtualEnv portion of the prompt, this adds ":venvname"
if ! test -z "$VIRTUAL_ENV" ; then
PS1="${PS1}(${COLOR_VENV}${VIRTUAL_ENV##*/}${COLOR_DIVIDER})"
fi
PS1="${PS1}\n${COLOR_DIVIDER}└─\$${Color_Off} "
} }
# Tell Bash to run the above function for every prompt
export PROMPT_COMMAND=set_bash_prompt export PROMPT_COMMAND=set_bash_prompt