Skip to content

Instantly share code, notes, and snippets.

@whaley
Created September 25, 2011 14:47
Show Gist options
  • Select an option

  • Save whaley/1240666 to your computer and use it in GitHub Desktop.

Select an option

Save whaley/1240666 to your computer and use it in GitHub Desktop.
#!/bin/bash
BASE_DIRECTORY=$HOME/opt/ec2/credentials/
function outputChoices {
local count=0
for directory in ${directories[@]}
do
echo -e "$count:\t$(basename $directory)"
((count++))
done
echo -n "Select one of [0-$numberOfDirectories] - any other input leaves creds unchanged: "
}
function changeCredDirectory {
if [[ -n $(echo -n $inputChoice | grep '^[0-9][0-9]*$') && $inputChoice -ge 0 && $inputChoice -le $numberOfDirectories ]]
then
newCredDirectory=${directories[$inputChoice]}
ln -nsf $newCredDirectory $BASE_DIRECTORY/current
echo; echo "Credentials set to $newCredDirectory"
else
echo ;echo "Invalid selection - creds unchanged"
fi
}
alias echo="echo -e"
directories=($(find $BASE_DIRECTORY -type d -maxdepth 1 -mindepth 1))
numberOfDirectories=$(( ${#directories[@]} - 1 ))
outputChoices
read inputChoice
changeCredDirectory
unalias echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment