Last active
January 29, 2026 13:13
-
-
Save noizo/f9b9fb4ce420885f74308193ab70405b to your computer and use it in GitHub Desktop.
awsume wrapper with console-plugin and multicontainer firefox profiles + eks function to select a cluster and a namespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| as() { | |
| local profile="$1" | |
| # export FIREFOX="/Applications/Firefox.app/Contents/MacOS/firefox" | |
| export FIREFOX="/Applications/Zen.app/Contents/MacOS/zen" | |
| # awsume wrapper function | |
| # pipx install awsume | |
| # pipx inject awsume awsume-console-plugin | |
| # https://addons.mozilla.org/en-US/firefox/addon/multi-account-containers/ | |
| # https://addons.mozilla.org/en-US/firefox/addon/open-url-in-container/ | |
| # curl -sL https://raw.githubusercontent.com/honsiorovskyi/open-url-in-container/master/bin/launcher.sh | sudo tee ~/.local/bin/firefox-container > /dev/null | |
| # chmod +x ~/.local/bin/firefox-container | |
| # | |
| # .awsume/config.yaml | |
| # colors: true | |
| # console: | |
| # browser_command: ~/.local/bin/firefox-container --orange --fingerprint --name={profile} "{url}" | |
| # fuzzy-match: true | |
| # role-duration: 0 | |
| # If no arguments were passed, use fzf to select a profile and exit early | |
| if [[ -z "${profile}" ]]; then | |
| profile=$(awsume -l | awk 'NR > 4 {print $1}' | fzf) | |
| . awsume "${profile}" | |
| return | |
| fi | |
| shift # Shift the arguments now that we know at least one was provided | |
| # If profile is non-empty, use 'awsume' with the profile and any provided args | |
| if [[ -n "${profile}" ]]; then | |
| . awsume "${profile}" "$@" | |
| fi | |
| export EKS_PROFILE="${profile}" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| eks() { | |
| emulate -L zsh | |
| setopt local_options pipefail | |
| local skip_namespace=false | |
| local profile="${EKS_PROFILE:-}" | |
| local kubeconfig="${KUBECONFIG:-$HOME/.kube/config}" | |
| while getopts ":n" opt; do | |
| case ${opt} in | |
| n) skip_namespace=true ;; | |
| \?) echo "Usage: eks [-n]"; return 1 ;; | |
| esac | |
| done | |
| shift $((OPTIND -1)) | |
| # --- kubectx-like flow: pick an existing context first --- | |
| local ctx_list ctx sel ctx_profile ctx_region ctx_cluster | |
| ctx_list=$(kubectl config get-contexts -o name 2>/dev/null) | |
| if [[ -n "$ctx_list" ]]; then | |
| sel=$( | |
| { echo "[+ add/update context]"; printf "%s\n" "$ctx_list"; } \ | |
| | fzf --select-1 --exit-0 --no-multi --height=60% --prompt="Context> " --border | |
| ) | |
| else | |
| sel="[+ add/update context]" | |
| fi | |
| if [[ "$sel" == "[+ add/update context]" || -z "$sel" ]]; then | |
| # --- Discover/add context (old flow, tightened) --- | |
| if [[ -z "$profile" ]]; then | |
| profile="$(aws configure list-profiles | fzf --select-1 --exit-0 --no-multi)" | |
| [[ -z "$profile" ]] && { echo "No profile"; return 1; } | |
| export AWS_PROFILE="$profile" | |
| export EKS_PROFILE="$profile" | |
| fi | |
| local allowed_regions_str="${EKS_ALLOWED_REGIONS:-us-east-1 us-west-2}" | |
| local -a allowed_regions; allowed_regions=(${=allowed_regions_str}) | |
| local region="${EKS_REGION:-${AWS_REGION:-${AWS_DEFAULT_REGION:-us-east-1}}}" | |
| if [[ " ${allowed_regions[*]} " != *" ${region} "* ]]; then | |
| region="us-east-1" | |
| fi | |
| local cluster | |
| cluster=$( | |
| aws eks list-clusters --region "$region" --output json 2>/dev/null \ | |
| | jq -r '.clusters[]' \ | |
| | fzf --select-1 --exit-0 --no-multi --height=60% --prompt="Cluster(${region})> " | |
| ) | |
| [[ -z "$cluster" ]] && { echo "No cluster"; return 1; } | |
| (( ${#cluster} > 100 )) && { echo "Cluster name too long"; return 1; } | |
| aws eks describe-cluster --region "$region" --name "$cluster" --query 'cluster.name' --output text >/dev/null 2>&1 \ | |
| || { echo "describe-cluster failed for [$cluster]"; return 1; } | |
| local ctx_alias="${profile}/${region}/${cluster}" | |
| aws eks update-kubeconfig \ | |
| --region "$region" \ | |
| --name "$cluster" \ | |
| --alias "$ctx_alias" \ | |
| --kubeconfig "$kubeconfig" \ | |
| --profile "$profile" >/dev/null \ | |
| || { echo "update-kubeconfig failed"; return 1; } | |
| kubectl config use-context "$ctx_alias" >/dev/null || { echo "Failed to use context"; return 1; } | |
| echo "Context: $ctx_alias KUBECONFIG: $kubeconfig" | |
| else | |
| # --- Switch to an existing context and also switch AWS account via `as` --- | |
| # Expected alias format from our updater: profile/region/cluster | |
| ctx="$sel" | |
| if [[ "$ctx" == */*/* ]]; then | |
| ctx_profile="${ctx%%/*}" | |
| local rest="${ctx#*/}" | |
| ctx_region="${rest%%/*}" | |
| ctx_cluster="${rest#*/}" | |
| if typeset -f as >/dev/null; then | |
| as "$ctx_profile" | |
| export AWS_REGION="$ctx_region" | |
| export AWS_DEFAULT_REGION="$ctx_region" | |
| export EKS_REGION="$ctx_region" | |
| else | |
| echo "Function 'as' not found; skipping AWS profile switch" >&2 | |
| fi | |
| else | |
| echo "Context '$ctx' doesn't encode profile/region; switching kube context only." >&2 | |
| fi | |
| kubectl config use-context "$ctx" >/dev/null || { echo "Failed to use context"; return 1; } | |
| echo "Context: $ctx KUBECONFIG: $kubeconfig" | |
| fi | |
| # Optional namespace picker | |
| if [[ "$skip_namespace" == false ]]; then | |
| local ns | |
| ns="$(kubectl get ns -o jsonpath='{.items[*].metadata.name}' | tr ' ' '\n' | fzf --select-1 --exit-0 --no-multi --height=60% --prompt="Namespace> " 2>/dev/null || true)" | |
| if [[ -n "$ns" ]]; then | |
| kubectl config set-context --current --namespace="$ns" >/dev/null || return 1 | |
| echo "Namespace: $ns" | |
| else | |
| echo "Namespace unchanged" | |
| fi | |
| else | |
| echo "Skipping namespace selection." | |
| fi | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment