feat(user/malte): sync notes and add git subcommand

This commit is contained in:
Malte Tammena 2024-03-07 15:33:56 +01:00
parent f674f24bf4
commit a9ad73bf6f

View file

@ -23,6 +23,8 @@ if [ -z "${1+x}" ]; then
if ! git diff --quiet "$year.md"; then
git add "$year.md"
git commit -m "Auto Commit $(date +"%F %R")"
export GIT_SSH_COMMAND="ssh -o BatchMode=yes"
(git pull --rebase && git push) || (echo "Sync failed" && exit 4) &
fi
# Exit
popd || exit 2
@ -45,9 +47,21 @@ function print_help_and_exit() {
printf " Show only todays entry\n"
printf " -1 | -2 | -3\n"
printf " Show only yesterday/the day before/etc\n"
printf " git GIT_COMMAND\n"
printf " Execute a git command in the note repository\n"
exit 1
}
function run_git_command_by_args_and_exit() {
# Switch directory
pushd "$XDG_DATA_HOME/life.md" || exit 1
# Run command
git "$@"
# Exit
popd || exit 2
exit
}
ONLY_TODOS=
ONLY_DONE=
ONLY_DAY=
@ -76,6 +90,10 @@ while [[ $# -gt 0 ]]; do
ONLY_DAY="$1days"
shift
;;
git)
shift
run_git_command_by_args_and_exit "$@"
;;
-h | --help)
print_help_and_exit
;;