Skip to content

Instantly share code, notes, and snippets.

@wouterdebie
Created May 20, 2019 16:41
Show Gist options
  • Save wouterdebie/a8f30e7326e9acb5738d27a1de2e67e6 to your computer and use it in GitHub Desktop.
Save wouterdebie/a8f30e7326e9acb5738d27a1de2e67e6 to your computer and use it in GitHub Desktop.
aws-vault wrapper that supports path completion (zsh)
#!/usr/bin/env bash
profile=$1
cmd=$2
src=$3
dst=$4
function _aws {
local profile=$1
local cmd=$2
local src=$3
local dst=$4
aws-vault exec ${profile} -- aws s3 ${cmd} ${src} ${dst}
}
case $cmd in
(cat)
_aws ${profile} cp s3://${src} -
;;
(complete)
if [[ $src != *\/* ]]; then
_aws ${profile} ls | awk '{print $NF}' | xargs -I {} echo '{}/'
else
dir=$(dirname $src)
if [[ ${dir} == "." ]] || [[ $src == *\/ ]]; then
prefix=$src
else
prefix="${dir}/"
fi
_aws ${profile} ls $prefix | awk '{print $NF}' | xargs -I {} echo "$prefix{}"
fi
;;
(login)
(*)
_aws ${profile} ${cmd} ${src} ${dst}
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment