Open luckmy46 opened 2 years ago
I just ran into this after upgrading to Monterey. After I figured out what was going on, and looking at the kubecontext.1s.py
script, I decided it was "easier" to just rewrite it in bash
:
#!/usr/bin/env bash
# Bash port of:
# https://github.com/matryer/xbar-plugins/blob/main/Dev/Kubernetes/kubecontext.1s.py
# <xbar.title>Kubeconfig Context Changer</xbar.title>
# <xbar.version>v1.0</xbar.version>
# <xbar.author>Jeebak Kim</xbar.author>
# <xbar.author.github>jeebak</xbar.author.github>
# <xbar.desc>Displays active kubeconfig context and allows you to easily change contexts.</xbar.desc>
# <xbar.dependencies>bash,kubectl</xbar.dependencies>
# I have kubectl installed via asdf
[[ -d $HOME/.asdf/shims ]] && export PATH="/usr/local/bin:/usr/bin:$HOME/.asdf/shims:$PATH"
KUBECTL="$(command -v kubectl)"
# :r! curl -s https://avatars3.githubusercontent.com/u/13629408?s=20 | base64
ICON="iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAECUlEQVR4nIyUfUxb5RfHv/et93Jv6S200LUZ4/cDlG5DHbRsRBbNdIkhLJkzhEUNGiVqRIOCEV/iTIxLjC4uy3QzYQtm+2MSMmMccRJQJy4kMHEIi45NkBfHGGMtbWnL7cvtNfdpysvAZSe5yc1znufznPM95zk07sJoQ7qgf3ezl7mTk5PsVkdZ07v/f+xoW3bxS41smkVSPMNDiVhw4b/OUGst8ua89baSujcynVUv0IxBWu5LqJGg9/LpYzMXjx6M+Meu3REoWDbmr3PXv51RsOsZimYMqfWSfA4agIHR2OJeLaFG5kbaT97oP/yx4hkeXZWyzV3/Wl5F8xnR6nRTFL1CCmcOB56jMH5TXYqEotk0i9NlLaqp09SoLzR94cIKYO7Owyc4Qc7OTKcRiWvQNMBmplHziISqcgmuAh6WdBqTs3GEIxoYGsgw0lCioA2m3P/NDh4/onPYpPg2qyDnFOr/7gIDyjfzuDQWQ92udHzfv4ApT5xcoF/W+pYVn7XPw1VgwLkhBT8NRsCbcjZyos0SC894SNtI9q0PpiLtHFAwMBLFO3tlnPo5iANfBzDtVTHlUfFRWwCne8LY96QZfVciBJZMn4JkdxMGARrtpduXa7azWMBX3UHsfUjC+0/JKFzPER0/rJHxeJmI1u4QHt2StqK6KSBJWXJsLU85WBpw3SOgqeUGWrvDONFoQSCskX7It7N49lMPfKEEOvevA0WBSJEEliaBNCcJonWTa7F19GbRgMrSNJRv4mFMY9Dc4SdFeH23jKYqE3r+jICmAJ6DXhRiYlaRm2IEjhVtxS6KZnl98cUKIwrsLLn54ft4XByJIrCQQFOVTA6194UxPhPH9s082fPB02aMTsfR3BEEzRhE0balhGWFDEsqujO9YczMJdCwR4UkUGjpCuFArRkd/WEivMhT+LIrhJwsBm3ngzj4zTyy5aVxoLMYZW70L8mxzcWbNtwbVJKCXJqI4ZVKE3KzWey4X0DDsTlS1cYnTMiSGWwr5PHeSR+icSAUSZ4JTP7y7XTfJ/vJ02OETNlZfbaXlzc4U7dZTTQ+fzkTDgtDYLr4ZU4e1z0qXv3Ci1uBxGJkEf/k5eG2ijJVmQuQeFXF6//7bO0eNbYQSG3SK/nPbBzPH/Lgh98V/DiooPaQBxM34/AFl2BqLOQb/e653TpsxdOLh2dvRf0Tf5jzK6spiqJ1nQILGn69GiXC6593PgGWAcJRjbSSpmnqeGd9dXCqpzfFWTEEFO+VqzQrakZH6Q5/SCOQ221kOp7sSwAzvx3ZNzt0vGW5f9WAnb/Wc17MfsApmPOKVtGWmW+s69TkuTcbSNMuszUHrL7MGR2ZeupreTVNS8SC1723w3T7NwAA//+pzItb8v6OkgAAAABJRU5ErkJggg=="
CONTEXTS="$("$KUBECTL" config get-contexts --no-headers)"
read -r __ CURRENT __ < <(grep '^\*' <<< "$CONTEXTS")
echo "${CURRENT:-Not set} | image=${ICON}"
echo "---"
while read -r name __; do
echo "$name | bash='$KUBECTL' param1=config param2=use-context param3='$name' refresh=true terminal=false"
done < <(grep -v '^\*' <<< "$CONTEXTS")
fao @copland -
'/Users/USER/Library/Application Support/xbar/plugins/001-kubecontext.1s.py' Traceback (most recent call last): File "/Users/USER/Library/Application Support/xbar/plugins/001-kubecontext.1s.py", line 60, in
CONTEXTS = load_contexts()
File "/Users/luc/Library/Application Support/xbar/plugins/001-kubecontext.1s.py", line 34, in load_contexts
lines = out.split('\n')
TypeError: a bytes-like object is required, not 'str'