#!/bin/bash

# edit the system log located in the docs repo, but also find the docs repo based on what ~/todo points to
log() {
   DOCS_REPO="${DOCS_REPO:-$(git -C "$(dirname "$(realpath ~/todo)")" rev-parse --show-toplevel)}"
   LOG_FILE=system-log
   LOG_FILE_PATH="$DOCS_REPO/$LOG_FILE"

   if git -C "$DOCS_REPO" pull; then
      $EDITOR "$LOG_FILE_PATH"
      git -C "$DOCS_REPO" commit -m "$LOG_FILE" "$LOG_FILE_PATH"
   else
      $EDITOR "$LOG_FILE_PATH"
   fi
}