From a9ad73bf6f29b2dd5bf58101721b409c97af21f7 Mon Sep 17 00:00:00 2001 From: Malte Tammena Date: Thu, 7 Mar 2024 15:33:56 +0100 Subject: [PATCH] feat(user/malte): sync notes and add `git` subcommand --- scripts/note.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/scripts/note.sh b/scripts/note.sh index 4c65865..3a2ddbb 100755 --- a/scripts/note.sh +++ b/scripts/note.sh @@ -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 ;;