Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Commit with gpg without having to always remember -S
#!/bin/bash
EXISTS="`git config --global --list | sed -n "/.*signingkey.*/p"`"
if [ -z $EXISTS ]
then
echo "Woops ! It seems you dont have your git signed. Looking for an existing GPG key..."
SIGNING_KEY="`gpg --list-keys | sed -n '3p' | sed "s/.*\///" | sed "s/ .*//"`"
if ! [ -z "$SIGNING_KEY" ]; then
echo "GPG Key found ! Using: $SIGNING_KEY"
git config --global user.signingkey "$SIGNING_KEY"
echo "Configured your global user with the key :)"
EXISTS="exists"
else
echo "GPG Key not found :( Create one with: gpg --gen-key"
fi
fi
if ! [ -z $EXISTS ]; then
git commit -S
fi
@saantiaguilera

This comment has been minimized.

Copy link
Owner Author

@saantiaguilera saantiaguilera commented Oct 1, 2016

Add this to somewhere PATH can access. This works for OS X, best path to place it is under /usr/local/bin/ :)

Remember permissions ! If you place it in /usr/local/bin/ since everyone can have access to the scripts, give the commit script all type of permissions

chmod +x commit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment