Updated fix-kubectl, added load-zellij

This commit is contained in:
Lockszmith 2023-11-08 18:47:13 -05:00
parent c6022128ec
commit 0c20efd44d
2 changed files with 56 additions and 9 deletions

View File

@ -1,5 +1,7 @@
#! /usr/bin/env bash
if [[ "$0" == "$SHELL" ]]; then
BASE_0="$(basename ${0#-})"
BASE_SHELL="$(basename "$SHELL")"
if [[ -z "${BASE_0}" || "${BASE_0}" == "$BASE_SHELL" ]]; then
if [[ -z "FIX_KUBECTL_RECALL" ]]; then
unset kubectl 2>/dev/null || unalias kubectl 2>/dev/null || true
@ -35,17 +37,34 @@ if [[ "$0" == "$SHELL" ]]; then
if [[ -n "$(type -t 'kubectl-cnpg')" ]]; then
. <( kubectl cnpg completion ${SHELL##*/} )
else
CNPG_VER="${CNPG_VER:-1.20.2}"
DL_VER=1.18.1
GH_URL=https://github.com/cloudnative-pg/cloudnative-pg
DEB_FILE="kubectl-cnpg_${CNPG_VER}_linux_x86_64.deb"
URL=${GH_URL}/releases/download/v${CNPG_VER}/${DEB_FILE}
DL_FILE="kubectl-cnpg_${DL_VER}_linux_x86_64.deb"
URL=${GH_URL}/releases/download/${DL_VER}/${DL_FILE}
printf '%s\n' \
'To download adn install cnpg kubectl plugin, run:' \
" wget ${URL}" \
" sudo dpkg -i $DEB_FILE"
'To download and install cnpg kubectl plugin, run:' \
" curl -sSLO ${URL}" \
" sudo dpkg -i $DL_FILE"
fi
if [[ -z "$(type -t 'kubetui')" ]]; then
DL_VER='v1.4.2'
GH_URL=https://github.com/sarub0b0/kubetui
DL_FILE=kubetui-x86_64-unknown-linux-musl-rustls
URL=${GH_URL}/releases/download/${DL_VER}/${DL_FILE}
printf '%s\n' \
'To download and install kubetui, run:' \
" curl -sSL ${URL} > ~/bin/kubetui" \
" chmod +x ~/bin/kubetui"
fi
if [[ -z "$(type -t 'k3s')" ]]; then
printf '%s\n' \
'To download and install k3s, run:' \
" curl -sS https://webinstall.dev/k9s | bash"
fi
if [[ -n "$(type -t 'k3s')" ]]; then
. <( k3s completion ${SHELL##*/} )
fi
@ -59,9 +78,9 @@ if [[ "$0" == "$SHELL" ]]; then
}
fi
elif [[ "$1" == '-' ]]; then
cat $0
cat "${BASH_SOURCE[0]}"
else
SCRIPT_NAME="$(basename $0)"
SCRIPT_NAME="$BASE_0"
printf '%s\n' \
"It seems $SCRIPT_NAME was invoked as a script. It should be sourced instead." \
'The easiest way is to call it like this:' \

28
load-zellij Executable file
View File

@ -0,0 +1,28 @@
#! /usr/bin/env bash
BASE_0="$(basename ${0#-})"
BASE_SHELL="$(basename "$SHELL")"
if [[ -z "${BASE_0}" || "${BASE_0}" == "$BASE_SHELL" ]]; then
zellij() {
if [[ -x /tmp/zellij/bootstrap/zellij ]]; then
/tmp/zellij/bootstrap/zellij "${@}"
else
bash <(curl -sL zellij.dev/launch) "${@}"
fi
}
. <( zellij setup --generate-completion "$BASE_SHELL" )
if [[ -z "$ZELLIJ_SESSION_NAME" ]]; then
(zellij list-sessions 2&>1) > /dev/null || zellij attach -c $USER@$(hostname)
fi
elif [[ "$1" == '-' ]]; then
cat "${BASH_SOURCE[0]}"
else
SCRIPT_NAME="$BASE_0"
printf '%s\n' \
"It seems $SCRIPT_NAME was invoked as a script. It should be sourced instead." \
'The easiest way is to call it like this:' \
" $ . <( $SCRIPT_NAME - ) # Note the '-' after the script's name" \
''
fi