Last active
January 27, 2017 18:26
-
-
Save Phrozyn/7b295f93e05ea4b368e009bcc5bffad1 to your computer and use it in GitHub Desktop.
An alias to ansible-vault encrypt and git add in the same command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create a .bash_aliases in your home dir and add the following (changing to your username of course | |
alias git-add='/Users/<username>/gitadd-ansiblevault.sh' | |
# Add the following to your .bash_profile (this will only ever need to be added back in if you update bash) | |
source ~/.bash_aliases | |
#Add the following script to your home dir (usually /Users/<username> | |
# This could definitely be improved to add a check for file-type | |
--------------------------------------------------------------------- | |
#!/bin/sh | |
# Some parts of "vault-merge" by Benjamin Ragheb <[email protected]> | |
# were used in this script | |
# Alicia L Smith <[email protected]> | |
# First, we ensure we are inside the working directory of a git repo. | |
GIT_ROOT=`git rev-parse --show-toplevel` | |
if [ $? != 0 ]; then | |
exit $? | |
fi | |
CHECK_ENCRYPTION=`grep -irl "ANSIBLE_VAULT" $GIT_ROOT | grep $1` | |
if [ "$CHECK_ENCRYPTION" == $1 ] && [ $1 | |
then | |
ansible-vault encrypt $1 || exit $? | |
git add $1 | |
echo "$VAULT_FILE has been updated." | |
echo " (or re-run this command to retry the encryption)" | |
exit 0 | |
else | |
echo "This file is already encrypted." | |
git add $1 | |
echo "Updated local git with file changes." | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment