mirror of
https://github.com/nikdoof/dotfiles.git
synced 2025-12-21 23:09:21 +00:00
[shell-common] Support fzf on awslogin
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
# Get the list of AWS profiles
|
# Get the list of AWS profiles
|
||||||
function awsprofiles() {
|
function awsprofiles() {
|
||||||
profiles=$(aws --no-cli-pager configure list-profiles 2> /dev/null)
|
profiles=$(aws --no-cli-pager configure list-profiles 2> /dev/null)
|
||||||
@@ -28,19 +27,47 @@ function awslogin() {
|
|||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Unknown option: $1"
|
echo "Unknown option: $1"
|
||||||
echo "Usage: awslogin --profile prof [--region region]"
|
echo "Usage: awslogin [--profile prof] [--region region]"
|
||||||
return 1
|
return 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# Check if profile is provided
|
# Get available profiles
|
||||||
if [[ -z "$profile" ]]; then
|
local available_profiles
|
||||||
echo "Error: --profile parameter is required."
|
available_profiles=$(aws --no-cli-pager configure list-profiles 2> /dev/null)
|
||||||
echo "Usage: awslogin --profile prof [--region region]"
|
if [[ -z "$available_profiles" ]]; then
|
||||||
|
echo "No AWS profiles found in ~/.aws/config"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# If no profile provided, use fzf to select one
|
||||||
|
if [[ -z "$profile" ]]; then
|
||||||
|
profile=$(echo "$available_profiles" | fzf --header "Select AWS profile" --height 40%)
|
||||||
|
if [[ -z "$profile" ]]; then
|
||||||
|
echo "No profile selected."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# Check if provided profile exists
|
||||||
|
if ! echo "$available_profiles" | grep -qx "$profile"; then
|
||||||
|
echo "Profile '$profile' not found. Searching for matches..."
|
||||||
|
local matched_profiles
|
||||||
|
matched_profiles=$(echo "$available_profiles" | grep -i "$profile")
|
||||||
|
|
||||||
|
if [[ -z "$matched_profiles" ]]; then
|
||||||
|
echo "No matching profiles found."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
profile=$(echo "$matched_profiles" | fzf --header "Select AWS profile" --height 40%)
|
||||||
|
if [[ -z "$profile" ]]; then
|
||||||
|
echo "No profile selected."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Build AWS CLI options
|
# Build AWS CLI options
|
||||||
local aws_opts=()
|
local aws_opts=()
|
||||||
[[ -n "$profile" ]] && aws_opts+=(--profile "$profile")
|
[[ -n "$profile" ]] && aws_opts+=(--profile "$profile")
|
||||||
|
|||||||
Reference in New Issue
Block a user