From e24e8a1c49837cfbc9d0d96576d60bcb50a844ac Mon Sep 17 00:00:00 2001 From: "Andrew R. M" Date: Tue, 8 Apr 2025 15:29:13 +0000 Subject: [PATCH] Add prompt generation commands for git/kubernetes --- bash/.functions | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/bash/.functions b/bash/.functions index 41c5043..5b3ebbe 100644 --- a/bash/.functions +++ b/bash/.functions @@ -18,6 +18,49 @@ maths() cat_with_newline() { - cat "$@" && echo + \cat "$@" && echo } alias cat="cat_with_newline" + +k_prompt() +{ + set -x + if [ -z ${KUBE_PROMPT+x} ]; then + export KUBE_PROMPT=1 + else + unset KUBE_PROMPT + fi + set +x +} + +kube_prompt() +{ + set -x + if ! [ -z ${KUBE_PROMPT+x} ]; then + context=$(\cat ${KUBECONFIG} \ + | grep "current-context: " \ + | sed "s/current-context: //") + echo {$context} + fi + set +x +} + +g_prompt() +{ + if ! [ -z ${GIT_PROMPT+x} ]; then + export GIT_PROMPT=1 + else + unset GIT_PROMPT + fi +} + +git_prompt() +{ + if ! [ -z ${GIT_PROMPT+x} ]; then + # Determine if we are in a git repository + if git rev-parse --is-inside-work-tree &> /dev/null; then + branch=$(git rev-parse --abbrev-ref HEAD) + echo [$branch] + fi + fi +}