Skip to content
This repository was archived by the owner on Mar 15, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions ktx
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,29 @@ ktx() {

# If no argument was given then list the files in $HOME/.kube
if [ -z "$1" ]; then
opts="none\n"
for kube in $(find "${HOME}/.kube" -maxdepth 1 -type f -o -type l); do
if [[ "${KUBECONFIG}" == "$kube" ]]; then
echo -n "(active) "
opts="$opts(active) "
fi
echo $(basename "${kube}")
opts=${opts}$(basename "${kube}")"\n"
done

# if fzf is installed, use it to choose the context
if type fzf &>/dev/null ; then
choice=$(echo $opts | fzf)
else
echo -n $opts
return
fi
if [ ! -z "$choice" ] ; then
if [[ "$choice" == "none" ]] || [[ "$choice" == "None" ]]; then
unset KUBECONFIG
return
fi
export KUBECONFIG="${HOME}/.kube/${choice}"
fi

return
fi

Expand Down
1 change: 1 addition & 0 deletions ktx-completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ KUBECONFIG_DIR=${KUBECONFIG_DIR:-"${HOME}/.kube/"}
_getconf()
{
find ${KUBECONFIG_DIR} -maxdepth 1 \( -type f -o -type l \) -exec basename {} \;
echo "none"
}

_ktx() {
Expand Down