From 402aa8d44987d03d9c52efa504042dd8a9d3729f Mon Sep 17 00:00:00 2001 From: Gerrit Pannek Date: Fri, 24 May 2024 19:15:47 +0200 Subject: [PATCH] add functions --- dotfiles/functions | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 dotfiles/functions diff --git a/dotfiles/functions b/dotfiles/functions new file mode 100644 index 0000000..d66d914 --- /dev/null +++ b/dotfiles/functions @@ -0,0 +1,35 @@ +# Venv Switcher +VENV_BASE="${HOME}/.venv" +type python &>/dev/null && PY=python +type python3 &>/dev/null && PY=python3 + +mkdir -p "${VENV_BASE}" + +function create_venv { + if [ -d "${VENV_BASE}/$1" ] ; then + return + fi + + $PY -m venv "${VENV_BASE}/$1" +} + +function venv { + case "$1" in + l) ls -1 "${VENV_BASE}" | sed 's/^/\ \-\ /g' ;; + c) create_venv $2 ; shift ;; + s) create_venv $2 ; shift ; source "${VENV_BASE}/$1/bin/activate" ;; + *) source "${VENV_BASE}/$1/bin/activate" ;; + esac + + if [ -n "$1" ] ; then + export PATH=$PATH:${VENV_BASE}/$1/bin + fi +} + +function kubeprune { + for ns in $(kubectl get ns | awk '{ print $1 }'); do + for pod in $(kubectl get $1 -n $ns 2>/dev/null | grep $2 | awk '{ print $1}'); do + kubectl delete $1 -n $ns $pod + done + done +}