diff --git a/zsh/custom.zsh b/zsh/custom.zsh index c464261..eb81ed7 100644 --- a/zsh/custom.zsh +++ b/zsh/custom.zsh @@ -48,3 +48,23 @@ swth() source ~/.zshrc fi } + +awscreds() { + SSOFILE=~/.aws/sso/cache/$(\ls -t ~/.aws/sso/cache | head -n 1) + CACHEFILE=~/.aws/cli/cache/$(\ls -t ~/.aws/cli/cache | head -n 1) + + export AWS_ACCESS_KEY_ID="$(jq -r '.Credentials.AccessKeyId' $CACHEFILE)" AWS_SECRET_ACCESS_KEY="$(jq -r '.Credentials.SecretAccessKey' $CACHEFILE)" + export AWS_SESSION_TOKEN="$(jq -r '.Credentials.SessionToken' $SSOFILE)" +} + +s3bat() { + # create temporary folder + path_hash=$(echo -n "$1" | sha256sum | head -c 64) + tmpfile="/tmp/${path_hash}" + # check if tmpfile already exists + if [[ ! -a "$tmpfile" ]]; then + aws --profile backend s3 cp --request-payer requester $1 "$tmpfile" + fi + + bat "$tmpfile" +}