Skip to content

Instantly share code, notes, and snippets.

@tayopal
Created December 7, 2022 22:29
Show Gist options
  • Save tayopal/57c09f7b33263354eb0a503395bb1dd8 to your computer and use it in GitHub Desktop.
Save tayopal/57c09f7b33263354eb0a503395bb1dd8 to your computer and use it in GitHub Desktop.
#! /usr/bin/env zsh
function saws()
{
valid_profiles=($(~/.local/bin/parse_aws_config))
if [ -z "$1" ]; then
# Maybe just echo what profile is _still_ active
echo "Current profile is: $AWS_PROFILE"
return 0
fi
if [[ ! " ${valid_profiles[@]} " =~ " ${1} " ]]; then
echo "Invalid profile name provided"
return -1
# commands here when array doesn't contains a value
fi
export AWS_PROFILE=$1
echo "Profile changed to: $AWS_PROFILE"
}
_saws_completions()
{
COMPREPLY+=($(~/.local/bin/parse_aws_config))
}
complete -F _saws_completions saws
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment