-
Notifications
You must be signed in to change notification settings - Fork 1
/
git-newb
executable file
·40 lines (32 loc) · 1.32 KB
/
git-newb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
# Copyright (c) 2019-2020 Benjamin Holt -- MIT License
if [ "$1" == "-h" -o "$1" == "--help" ]; then
cat <<USAGE
usage: git newb SLUG [ALIAS] Creates a new git branch named ALIAS and
immediately pushes it to a remote branch
named prefix/SLUG ALIAS defults to initials
from the SLUG
git newb -h|--help Print this message and exit
USAGE
exit 0
fi
# Bold=`tput bold`
# Off=`tput sgr0`
if [ -z "$1" ]; then
echo "Must specify a slug for the new branch name" >&2
exit 1
fi
Slug="$1"
# Alias="${2:-`echo "$Slug" | sed -e 's:.*/::'`}" # Derrive default alias from last segment of the slug
Alias="${2:-`echo "$Slug" | sed -e 's:.*/::g' -e 's/[A-Z]*-*[0-9][0-9]*//' | tr -d 'a-z0-9_.-' | tr 'A-Z' 'a-z'`}" # Derive default alias from UpperCaseInitials (ignoring any JIRA-123- prefix)
if [ -z "$Alias" ]; then
Alias=`echo "$Slug" | sed -e 's:.*/::g' -e 's/[A-Z]*-*[0-9][0-9]*//' -e 's/^\([A-Za-z]\)[^_.-]*/\1/' -e 's/[_.-]\([A-Za-z]\)[^_.-]*/\1/g'` # Derive default alias from dash-separated-initials (again ignoring JIRA-123-)
fi
Branch=`git branch --list "$Alias"`
if [ "$Branch" ]; then
echo "$Alias: branch already exists" >&2
exit 1
fi
git checkout -b "$Alias"
git-setupb "$Slug" "$Alias"
###