diff --git a/bin/git-c b/bin/git-c index 0dd93ac..dc3a78d 100755 --- a/bin/git-c +++ b/bin/git-c @@ -1,8 +1,16 @@ #!/bin/bash -e +### Fix committer email by repo + +git setmail >/dev/null + +### Commit + vault-gpg $(grep default-key ~/.gnupg/gpg.conf | cut -d ' ' -f 2) git commit -S -v "$@" +### Count productivity habit + PROD_TASK=$(habitica https://habitica.com/api/v3/tasks/user | jq -r '.data | map(select(.text=="productivity").id)[0]') if ! ( habitica -sS -o /dev/null -X POST https://habitica.com/api/v3/tasks/${PROD_TASK}/score/up ); then diff --git a/bin/git-setmail b/bin/git-setmail new file mode 100755 index 0000000..0771aaa --- /dev/null +++ b/bin/git-setmail @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 + +# Usage: git setmail myemail@example.com:"github.com:myprefix" myothermail@example.com:".*" +# +# Configuration format: One combination per line `:` + +import sys, re, subprocess, os.path + +CONFIG=os.path.expanduser('~/.config/git-setmail.conf') + +def main(): + try: + repo = [x.split()[1] for x in subprocess.check_output(['git', 'remote', '-v'], universal_newlines=True).split('\n') if re.match('origin.*\(push\)', x)][0] + except: + print('Could not find origin, not setting email.') + return 1 + + combinations = sys.argv[1:] + if len(combinations) == 0: + if os.path.isfile(CONFIG): + combinations = open(CONFIG).read().split('\n') + else: + print('Neither CLI arguments nor config ({}) found.'.format(CONFIG)) + return 1 + + for combi in combinations: + email, match = combi.split(':', 1) + if re.search(match, repo): + if email == subprocess.check_output(['git', 'config', 'user.email'], universal_newlines=True).strip(): + print('Email correctly set to "{}", not modifying.'.format(email)) + else: + print('Found repo "{}", setting email to "{}"...'.format(repo, email)) + subprocess.check_call(['git', 'config', 'user.email', email]) + break + + return 0 + +if __name__ == "__main__": + exit(main())