From b53f1ee586d423047b8520f41e0d4c24e9cf1e16 Mon Sep 17 00:00:00 2001 From: Hektor Misplon Date: Fri, 20 Jun 2025 15:03:58 +0200 Subject: [PATCH] Add 'git-cb' script --- .bin/git-cb | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 .bin/git-cb diff --git a/.bin/git-cb b/.bin/git-cb new file mode 100755 index 0000000..6bc47b7 --- /dev/null +++ b/.bin/git-cb @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +types=( + "feature For new features" + "bugfix For bug fixes" + "hotfix For urgent fixes" + "release For preparing releases" + "chore For non-code tasks" +) + +selected=$(printf '%s\n' "${types[@]}" | fzf --prompt="Select branch type: ") || exit 1 +type=${selected%% *} + +editor="${EDITOR:-vi}" +tmpfile=$(mktemp) + +cat > "$tmpfile" << 'EOF' +# Enter your branch description below in kebab case (e.g. `my-description`): + +EOF + +"$editor" "$tmpfile" + +desc=$(grep -v '^#' "$tmpfile" | tr -d '\n' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') +rm "$tmpfile" + +if [[ -z "$desc" ]]; then + echo "No description provided." + exit 1 +fi + +if [[ ! "$desc" =~ ^[a-z0-9]+(-[a-z0-9]+)*$ ]]; then + echo "Invalid branch description format." + echo "Use lowercase letters, numbers, and hyphens only." + echo "No trailing or consecutive hyphens allowed." + exit 1 +fi + +branch="$type/$desc" + +git checkout -b "$branch"