Skip to content

Instantly share code, notes, and snippets.

@saantiaguilera
Created October 1, 2016 03:12
Show Gist options
  • Save saantiaguilera/4901c02fcceb291247f25ff892eb8cb2 to your computer and use it in GitHub Desktop.
Save saantiaguilera/4901c02fcceb291247f25ff892eb8cb2 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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