Skip to content

Instantly share code, notes, and snippets.

@gnufied
Created February 12, 2019 21:32
Show Gist options
  • Save gnufied/b362fac1e0fb793688ae21db18d3beca to your computer and use it in GitHub Desktop.
Save gnufied/b362fac1e0fb793688ae21db18d3beca to your computer and use it in GitHub Desktop.
feanor_grab_current_context() {
if type "kubectl" > /dev/null; then
kube_context=$(kubectl config current-context 2>/dev/null)
if [[ -z $kube_context ]]; then
kube_context="no_kube"
fi
echo "$kube_context" > /tmp/current-kube-context
echo -n "$kube_context"
fi
}
feanor_custom_kube_context() {
if [[ -s "/tmp/current-kube-context" ]];then
local kube_context=$(cat "/tmp/current-kube-context")
if [[ -z $kube_context ]]; then
feanor_grab_current_context
fi
local current_ts=$(date '+%s')
local ftime=$(stat -c '%Y' "/tmp/current-kube-context")
local timediff=$(expr $current_ts - $ftime)
if [ $timediff -gt 300 ]; then
rm "/tmp/current-kube-context"
fi
echo -n "$kube_context"
else
feanor_grab_current_context
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment