Last active
October 17, 2021 19:06
-
-
Save unode/9366218 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Copyright 2014-2016 Renato Alves | |
# distributed under the GPLv3 licence | |
if [ -z "$TASKDIR" ]; then | |
#TODO Look for data location in rc:location instead of assuming ~/.taskrc | |
TASKDIR="$(grep data.location $HOME/.taskrc | cut -d '=' -f 2)" | |
if [[ "$TASKDIR" == "~/"* ]]; then | |
# Ensure ~/ is converted to $HOME since ~ as a string is not expanded | |
TASKDIR="${TASKDIR/\~\//$HOME\/}" | |
fi | |
# Any tilde expansion other than ~/ is not supported (~user/) for instance | |
if [[ "$TASKDIR" == "~"* ]]; then | |
echo 1>&2 "taskgit error: Your taskrc data.location uses a ~ pattern not supported: $TASKDIR" | |
echo 1>&2 "Consider replacing it by either ~/ or an absolute path." | |
exit 1 | |
fi | |
fi | |
if [ -z "$TASKBIN" ]; then | |
TASKBIN="task" | |
fi | |
if [ -d "$TASKDIR" ]; then | |
cd "$TASKDIR" | |
else | |
echo 1>&2 "taskgit error: Couldn't navigate to TASKDIR: $TASKDIR" | |
echo 1>&2 "Consider changing your taskrc data.location to use ~/ or an absolute path." | |
exit 1 | |
fi | |
"$TASKBIN" "$@" | |
EXITCODE=$? | |
if ! [ -d ".git" ]; then | |
git init 2>&1 > git.log | |
echo "git.log" > .gitignore | |
echo "git.log.old" >> .gitignore | |
echo "*.pem" >> .gitignore | |
git add .gitignore 2>&1 >> git.log | |
git add *.data *.theme 2>&1 >> git.log | |
git commit -a -m "Initial log" 2>&1 >> git.log | |
fi | |
if [ "$#" -gt "0" ]; then | |
git add *.data *.theme 2>&1 >> git.log | |
git commit -a -m "$*" 2>&1 >> git.log | |
fi | |
# Rotate git.log if bigger than 1M | |
if [ "$(stat -c '%s' git.log)" -gt "1000000" ]; then | |
mv -f git.log git.log.old | |
touch git.log | |
fi | |
exit $EXITCODE |
@andrey-utkin thanks for the suggestion.
Never noticed that ~/
was not properly expanded. Also learned that it's actually non-trivial to do it.
The newer version now addresses the problem and is a bit more user-friendly.
It now also uses bash explicitly as some of the changes are bash specific.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This change makes it support default-gejerated .taskrc with tild
~
in path: