Skip to content

Instantly share code, notes, and snippets.

@smook1980
Created November 14, 2024 20:34
Show Gist options
  • Save smook1980/ba7954c4c50272626813e82c227e6e4b to your computer and use it in GitHub Desktop.
Save smook1980/ba7954c4c50272626813e82c227e6e4b to your computer and use it in GitHub Desktop.
Launch the AWS console via aws-vault in a Chrome Profile for the given aws profile.
function aws-console --description 'start a new chrome browser logged in to aws'
# set to yes to always start in a new window
set -l NEW_WINDOW no
set -l profile "$argv[1]"
if test -z "$profile"
echo "Profile is a required argument" >&2
return 1
end
# replace / and whitespace with __
set -l profile_dir_name (string replace -ar '[\W/]' __ "$profile")
set -l set new_window_arg ''
if test "$NEW_WINDOW" = yes
set new_window_arg --new-window
end
set -l vault_login_arg ''
if set -q argv[2]; and test "$argv[2]" != --link
set vault_login_arg "-d$argv[2]"
else
set vault_login_arg -d1h
end
# echo "vault_login_arg: $vault_login_arg"
# run aws-vault
# --prompt osascript only works on OSX
#echo aws-vault login $profile "$vault_login_arg" --stdout --prompt osascript
set -l url (aws-vault login $profile "$vault_login_arg" --stdout --prompt osascript)
if test $status -ne 0
# fish will also capture stderr, so echo $url
echo "error running:"
echo aws-vault login $profile "$vault_login_arg" --stdout --prompt osascript
echo "got:"
echo $url >&2
return $status
end
if [ "$argv[-1]" = --link ]
echo "$url"
echo "Copied to clipboard"
echo "$url" | pbcopy
else
open -na 'Google Chrome' --args --profile-directory=$profile_dir_name --no-first-run --no-default-browser-check $new_window_arg $url
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment