# vim: syn=sh ts=4 sts=4 sw=4 smartindent autoindent expandtab ff=unix git-initialize() { USAGE="git-initialize -u USER -e EMAIL [-b DEFAULT_BRANCH] [-S SSH_KEY] [-s SSH_COMMAND]" args=$( getopt "b:e:s:S:u:" $* ) if [ $? -ne 0 ]; then echo "$USAGE" return 2 fi local default_branch=main local user="$USER" local email="" local ssh_key="" local ssh_command="" set -- $args while :; do case "$1" in -b) local default_branch="$2" shift; shift ;; -e) local email="$2" shift; shift ;; -S) local ssh_key="$2" shift; shift ;; -s) local ssh_command="$2" shift; shift ;; -u) local user="$2" shift; shift ;; --) shift; break ;; esac done if [ -z "$email" ]; then read -p "Email: " __git_email__ local email=$__git_email__ unset __git_email__ fi signingkey=$( gpgsm --list-secret-keys | egrep '(key usage|ID)' | grep -v CertifyID |grep -B 1 digitalSignature | awk '/ID/ {print $2}' ) git config --global user.name "$user" git config --global user.email "$email" git config --global init.defaultBranch "$default_branch" if [ -n "$ssh_command" ]; then git config --global core.sshCommand "$ssh_command" elif [ -n "$ssh_key" ]; then git config --global core.sshCommand "ssh -i \"$ssh_key\"" fi } git-init-smime() { USAGE="git-init-smime [-cgh] CERT_ID" args=$( getopt "cCgh" $* ) if [ $? -ne 0 ]; then echo $USAGE return 2 fi set -- $args local sign_commits="" local global="" while :; do case "$1" in -C) local sign_commits=NO shift ;; -c) local sign_commits=YES shift ;; -g) local global="--global" shift ;; -h) cat << EOF git-init-smime HELP SYNOPSIS $USAGE OPTIONS -C Disable automatic signing of commits. [DEFAULT: no change] -c Enable automatic signing of commits. [DEFAULT: no change] -g Set global GIT options. -h Print this help message and exit. EOF shift; return ;; --) shift; break ;; esac done if [ -z "$1" ]; then echo "No CERT_ID given! Obtain the ID with \"gpgsm --list-secret-keys\"" >&2 echo "$USAGE" return 2 fi git config $global user.signingkey "$1" git config $global gpg.format x509 if [ "$sign_commits" = "YES" ]; then git config $global commit.gpgsign true elif [ "$sign_commits" = "NO" ]; then git config $global commit.gpgsign false fi } git-init-gpg() { echo TODO } git-commit-timestamp() { winver=$(which winver) if [ -n "$WINVER" ]; then local hostname="$(hostname)" else local hostname="$(hostname)" fi local msg="$(date "+%Y.%m.%d %H:%M:%S") ($hostname)" git commit -m "$msg" } git-push-all() { local branch="$(git branch --show-current)" for __remote in $(git remote show); do git push "$__remote" "$branch" done unset __remote } git-tags-push() { for remote in $(git remote show); do git push --tags "$remote" done } git-mktag() { if [ $# -lt 1 ]; then echo "No tags given!" >&2 echo "SYNOPSIS:" echo " git-mkttag ..." fi while [ $# -gt 0 ]; do git tag "$1" shift done git-tags-push } # ALIASES alias gitdc='git-commit-timestamp' alias gpa='git-push-all' alias gittp='git-tags-push' alias gitmt='git-mktag' alias gitcb='git branch --show-current'