feat: git support
This commit is contained in:
55
src/main.sh
55
src/main.sh
@@ -114,6 +114,8 @@ if [ "${1:-}" = "--help" ]; then
|
|||||||
echo "Usage: $0 [--help | --new [FILTER..] | [FILTER..] ]
|
echo "Usage: $0 [--help | --new [FILTER..] | [FILTER..] ]
|
||||||
--help Show this help and exit
|
--help Show this help and exit
|
||||||
--new Create new entry and do not exit
|
--new Create new entry and do not exit
|
||||||
|
--git-init Activate git usage and exit
|
||||||
|
--git <cmd> Run git command and exit
|
||||||
|
|
||||||
[FILTER]
|
[FILTER]
|
||||||
You may specify any of these filters. Filters can be negated using the
|
You may specify any of these filters. Filters can be negated using the
|
||||||
@@ -131,6 +133,35 @@ if [ "${1:-}" = "--help" ]; then
|
|||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Git
|
||||||
|
if command -v "git" >/dev/null && [ -d "$ROOT/.git" ]; then
|
||||||
|
GIT="git -C $ROOT"
|
||||||
|
fi
|
||||||
|
if [ "${1:-}" = "--git-init" ]; then
|
||||||
|
shift
|
||||||
|
if [ -n "${GIT:-}" ]; then
|
||||||
|
err "Git already enabled"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
if ! command -v "git" >/dev/null; then
|
||||||
|
err "Git not installed"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
git -C "$ROOT" init
|
||||||
|
git -C "$ROOT" add -A
|
||||||
|
git -C "$ROOT" commit -m 'Initial commit: Start git tracking'
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
if [ "${1:-}" = "--git" ]; then
|
||||||
|
shift
|
||||||
|
if [ -z "${GIT:-}" ]; then
|
||||||
|
err "Git not supported, run \`$0 --git-init\` first"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
$GIT "$@"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
# Command line arguments to be self-contained
|
# Command line arguments to be self-contained
|
||||||
# Generate preview of file from selection
|
# Generate preview of file from selection
|
||||||
if [ "${1:-}" = "--preview" ]; then
|
if [ "${1:-}" = "--preview" ]; then
|
||||||
@@ -155,6 +186,10 @@ if [ "${1:-}" = "--delete" ]; then
|
|||||||
case $yn in
|
case $yn in
|
||||||
"yes")
|
"yes")
|
||||||
rm -v "$file"
|
rm -v "$file"
|
||||||
|
if [ -n "$GIT" ]; then
|
||||||
|
$GIT add "$file"
|
||||||
|
$GIT commit -q -m "File deleted" -- "$file"
|
||||||
|
fi
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
"no")
|
"no")
|
||||||
@@ -193,6 +228,10 @@ if [ "${1:-}" = "--new" ]; then
|
|||||||
tmpfile="$tmpmd.ics"
|
tmpfile="$tmpmd.ics"
|
||||||
awk -v uid="$uuid" "$AWK_NEW" "$tmpmd" >"$tmpfile"
|
awk -v uid="$uuid" "$AWK_NEW" "$tmpmd" >"$tmpfile"
|
||||||
mv "$tmpfile" "$file"
|
mv "$tmpfile" "$file"
|
||||||
|
if [ -n "$GIT" ]; then
|
||||||
|
$GIT add "$file"
|
||||||
|
$GIT commit -q -m "File added" -- "$file"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
rm "$tmpmd"
|
rm "$tmpmd"
|
||||||
fi
|
fi
|
||||||
@@ -205,6 +244,10 @@ if [ "${1:-}" = "--toggle-completed" ]; then
|
|||||||
tmpfile=$(mktemp)
|
tmpfile=$(mktemp)
|
||||||
awk "$AWK_ALTERTODO" "$file" >"$tmpfile"
|
awk "$AWK_ALTERTODO" "$file" >"$tmpfile"
|
||||||
mv "$tmpfile" "$file"
|
mv "$tmpfile" "$file"
|
||||||
|
if [ -n "$GIT" ]; then
|
||||||
|
$GIT add "$file"
|
||||||
|
$GIT commit -q -m "Completed toggle" -- "$file"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
# Increase priority
|
# Increase priority
|
||||||
if [ "${1:-}" = "--increase-priority" ]; then
|
if [ "${1:-}" = "--increase-priority" ]; then
|
||||||
@@ -215,6 +258,10 @@ if [ "${1:-}" = "--increase-priority" ]; then
|
|||||||
tmpfile=$(mktemp)
|
tmpfile=$(mktemp)
|
||||||
awk -v delta="1" "$AWK_ALTERTODO" "$file" >"$tmpfile"
|
awk -v delta="1" "$AWK_ALTERTODO" "$file" >"$tmpfile"
|
||||||
mv "$tmpfile" "$file"
|
mv "$tmpfile" "$file"
|
||||||
|
if [ -n "$GIT" ]; then
|
||||||
|
$GIT add "$file"
|
||||||
|
$GIT commit -q -m "Priority increased" -- "$file"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
# Decrease priority
|
# Decrease priority
|
||||||
if [ "${1:-}" = "--decrease-priority" ]; then
|
if [ "${1:-}" = "--decrease-priority" ]; then
|
||||||
@@ -225,6 +272,10 @@ if [ "${1:-}" = "--decrease-priority" ]; then
|
|||||||
tmpfile=$(mktemp)
|
tmpfile=$(mktemp)
|
||||||
awk -v delta="-1" "$AWK_ALTERTODO" "$file" >"$tmpfile"
|
awk -v delta="-1" "$AWK_ALTERTODO" "$file" >"$tmpfile"
|
||||||
mv "$tmpfile" "$file"
|
mv "$tmpfile" "$file"
|
||||||
|
if [ -n "$GIT" ]; then
|
||||||
|
$GIT add "$file"
|
||||||
|
$GIT commit -q -m "Priority decreased" -- "$file"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
# Reload view
|
# Reload view
|
||||||
if [ "${1:-}" = "--reload" ]; then
|
if [ "${1:-}" = "--reload" ]; then
|
||||||
@@ -339,6 +390,10 @@ if [ "$checksum" != "$(cksum "$filetmp")" ]; then
|
|||||||
file_new="$filetmp.ics"
|
file_new="$filetmp.ics"
|
||||||
awk "$AWK_UPDATE" "$filetmp" "$file" >"$file_new"
|
awk "$AWK_UPDATE" "$filetmp" "$file" >"$file_new"
|
||||||
mv "$file_new" "$file"
|
mv "$file_new" "$file"
|
||||||
|
if [ -n "$GIT" ]; then
|
||||||
|
$GIT add "$file"
|
||||||
|
$GIT commit -q -m "File modified" -- "$file"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
rm "$filetmp"
|
rm "$filetmp"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user