Skip to content

Instantly share code, notes, and snippets.

@toschneck
Created August 3, 2018 08:44
Show Gist options
  • Save toschneck/d702abce1c783d08cd9d53a6a2a5ac39 to your computer and use it in GitHub Desktop.
Save toschneck/d702abce1c783d08cd9d53a6a2a5ac39 to your computer and use it in GitHub Desktop.

Revisions

  1. toschneck created this gist Aug 3, 2018.
    41 changes: 41 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@

    # add this to your bash env

    # Set git user and signing key
    function git-set-user() {
    if [ "$#" -lt "1" ]
    then
    echo "Missing required arguments" >&2
    echo "Usage: $0 EMAIL [PATH_TO_GIT_REPO]" >&2
    exit 65
    fi

    USER_EMAIL="$1"
    USER_KEY=`gpg --with-colons -K "$USER_EMAIL" 2>/dev/null | awk -F: '$1 =="fpr" {print $10; exit}'`

    if [ -z "$USER_KEY" ]
    then
    echo "Unable to retrieve GPG key for $USER_EMAIL" >&2
    exit 1
    fi


    if [ -n "$2" ]
    then
    WORKING_DIR="$2"
    else
    WORKING_DIR="`pwd`"
    fi

    if [ ! -e "$WORKING_DIR/.git" ]
    then
    echo "Error: $WORKING_DIR is not a Git repository" >&2
    exit 1
    fi

    set -x

    git config --local user.email "$USER_EMAIL"
    git config --local user.signingkey "$USER_KEY"
    git config --local commit.gpgsign true
    }