Last active
August 22, 2023 16:38
-
-
Save aclima93/c685ea6ea10465c3da4db4aa27393a28 to your computer and use it in GitHub Desktop.
✨ pretty print ✨ the PR title from current git branch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# datetime | |
datetime=$(date +%d/%m/%Y) | |
# git branch name | |
branch_name=$(git rev-parse --abbrev-ref HEAD) | |
# for branches that follow the `<dir>/<ticket|NOJIRA>-<title>` naming convention and | |
# regex `(?<branch_dir>(\w+\/)+)?(?<ticket>(\w+-\d+)|(NOJIRA))[-//](?<title>(\w+-?)+)` | |
# e.g. `dev/TEST-123-The-short-title`, `dev/TEST-123/The-short-title`, `dev/NOJIRA-The-short-title` | |
# regex utils | |
d="[0-9]" | |
w="[a-zA-Z0-9_]" | |
branch_dir_regex="($w+\/)+" | |
ticket_regex=".*\/(($w+-$d+)|(NOJIRA))[-//].*" | |
title_regex=".*-$d+[-//](($w+-?)+)" | |
# regex matches using `sed` | |
branch_dir=$(sed -En "s/$branch_dir_regex/\1/p" <<< "$branch_name") | |
ticket=$(sed -En "s/$ticket_regex/\1/p" <<< "$branch_name") | |
full_title=$(sed -En "s/$title_regex/\1/p" <<< "$branch_name") | |
title=$(sed 's/-/ /g' <<< "$full_title") # replace all instances of '-' with ' ' in title | |
# output | |
echo "$datetime - $ticket - $title" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment