-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-bc.sh
More file actions
executable file
·61 lines (49 loc) · 1.75 KB
/
git-bc.sh
File metadata and controls
executable file
·61 lines (49 loc) · 1.75 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#! /usr/bin/env zsh
local commit_message=""
local branch_name=""
local prefix=$(git config stack.prefix)
# If default prefix is not set, prompt the user to set one
if [ -z "$prefix" ]; then
echo "No default prefix set."
vared -p "Enter default prefix: " -c prefix
git config stack.prefix "$prefix"
fi
# Check for the '-m' flag and capture the commit message
# Check for the '-m' flag
local has_message_flag=false
for arg in "$@"; do
if [ "$arg" = "-m" ]; then
has_message_flag=true
elif $has_message_flag; then
commit_message="$commit_message $arg"
has_message_flag=false
fi
done
echo "commit_message: $commit_message"
# If the '-m' flag was not provided, prompt for the commit message
if [ -z "$commit_message" ]; then
vared -p "Enter commit message: " -c commit_message
fi
if [ -z "$commit_message" ]; then
echo "No commit message provided."
exit 1
fi
# trim leading spaces on commit_message
commit_message=$(echo "$commit_message" | sed -e 's/^[[:space:]]*//')
# trim trailing spaces on commit_message
commit_message=$(echo "$commit_message" | sed -e 's/[[:space:]]*$//')
# trim quotation marks on commit_message
commit_message=$(echo "$commit_message" | sed -e 's/^"//' -e 's/"$//')
# Replace special characters and spaces in the commit message with underscores
branch_name=$(echo "$commit_message" | tr -s '[:space:]' '_' | tr -dc '[:alnum:]_' | sed 's/_*$//')
if [ -z "$branch_name" ]; then
echo "No branch name generated."
exit 1
fi
branch_prefix=$(eval echo $prefix)
full_branch_name="$branch_prefix-$branch_name"
echo "Creating branch $full_branch_name"
# Create a new branch from the commit message
git checkout -b "$full_branch_name"
# Create the commit with the given commit message
git commit $@