Skip to content

Instantly share code, notes, and snippets.

@sovrinbloc
Last active May 20, 2021 21:05
Show Gist options
  • Save sovrinbloc/18264641ca5491350531b1e550d5e55e to your computer and use it in GitHub Desktop.
Save sovrinbloc/18264641ca5491350531b1e550d5e55e to your computer and use it in GitHub Desktop.
Git Add Messages: Created Messages for every Git Add to Append to Git Commit
#!/bin/bash
# git-add script to accumulate git-add messages to append to git commit message
#
# Copyright May 20, 2021 Joseph Alai
#######################################
# Stage a file and append staging message
# to add to commit message.
#
# GLOBALS:
# files: filenames to stage
# ARGUMENTS:
# --message / -m
# OUTPUTS:
# Stages filenames
# Adds message to .gitmessage
# RETURN:
# 0 if print succeeds, non-zero on error.
#######################################
function git_add() {
files=()
while [ "$1" ];
do
file=$1
if [ "${1:0:1}" == "-" ]
then
shift
rev=$(echo "$file" | rev)
if [ -z "$1" ] || [ "${1:0:1}" == "-" ] || [ "${rev:0:1}" == ":" ]
then
bool=$(echo ${file:1} | sed s/://g)
booleans[$bool]=true
else
value=$1
flags[${file:1}]=$value
shift
fi
else
files+=("$file")
shift
fi
done
message="${flags["message"]}"
echo ${files[@]} >> .gitmessage
echo ...$message >> .gitmessage
git add "${files[@]}"
}
git_add "$@"
#!/bin/bash
# git-commit script to store accumulating git-add messages to the git-commit
#
# Copyright May 20, 2021 Joseph Alai
#######################################
# Commit staged files, append staging messages
# to the commit message.
#
# ARGUMENTS:
# --message / -m
# OUTPUTS:
# Commits staged files and combined messages
# RETURN:
# 0 if print succeeds, non-zero on error.
#######################################
function git_commit() {
args=()
while [ "$1" ];
do
arg=$1
if [ "${1:0:1}" == "-" ]
then
shift
rev=$(echo "$arg" | rev)
if [ -z "$1" ] || [ "${1:0:1}" == "-" ] || [ "${rev:0:1}" == ":" ]
then
bool=$(echo ${arg:1} | sed s/://g)
booleans[$bool]=true
else
value=$1
flags[${arg:1}]=$value
shift
fi
else
args+=("$arg")
shift
fi
done
message="${flags["message"]}"
commitMessage=$(cat .gitmessage)
git commit -m "$message
$commitMessage"
if [ $? -eq 0 ]; then
: > .gitmessage
else
echo "Could not successfully commit your changes."
fi
}
git_commit "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment