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 +}