git-commitizen 0.1.0-rc.1

A simple commitizen CLI tool in rust
Documentation
#!/usr/bin/env sh

# This script is used to write a conventional commit message.
# It prompts the user to choose the type of commit as specified in the
# conventional commit spec. And then prompts for the summary and detailed
# description of the message and uses the values provided. as the summary and
# details of the message.

usage() {
  echo "Usage: git cz [-a] [-h]"
  echo ""
  echo "Options:"
  echo "  -a  Automatically stage all modified and deleted files before committing."
  echo "  -h  Show this help message and exit."
  exit 1
}


# Check if the -a flag is supplied
AUTO_STAGE=false
while getopts "ah" flag; do
  case "${flag}" in
    a) AUTO_STAGE=true ;;
    h) usage ;;
    *) usage ;;
  esac
done

check_exit_status() {
  if [ $? -ne 0 ]; then
    echo "Aborted."
    exit 1
  fi
}

TYPE=$(gum choose "build" "ci" "chore" "docs" "feat" "fix" "perf" "refactor" "revert" "style" "test")
check_exit_status
SCOPE=$(gum input --placeholder "scope")
check_exit_status

# Since the scope is optional, wrap it in parentheses if it has a value.
test -n "$SCOPE" && SCOPE="($SCOPE)"

# Pre-populate the input with the type(scope): so that the user may change it
SUMMARY=$(gum input --value "$TYPE$SCOPE: " --placeholder "Summary of this change")
check_exit_status
DESCRIPTION=$(gum write --placeholder "Details of this change")
check_exit_status

display_text=$(printf "%s\n\n%s\n\nCommit changes?" "$SUMMARY" "$DESCRIPTION")

# Commit these changes if user confirms
if gum confirm "$display_text"; then
  if [ "$AUTO_STAGE" = true ]; then
    git commit -am "$SUMMARY" -m "$DESCRIPTION"
  else
    git commit -m "$SUMMARY" -m "$DESCRIPTION"
  fi
fi