#!/usr/bin/env bash
#
# dependencies: gum | mods
# source: https://github.com/meowgorithm/dotfiles

diff="$(git diff)"

if [ -z "${diff}" ]; then
  printf "%s\n" "No diff."
  exit 1
fi

msg="$(
  printf "%s" "${diff}" | \
  mods "write a commit message for this diff" | \
  sed -z '$ s/\n$//' | \
  gum write \
    --header "  Look ok? Ctrl+D to commit, or Ctrl+C to cancel" \
    --prompt.foreground "240"
)"

if [ -z "${msg}" ]; then
  exit 1
fi

git commit -am "${msg}"
