Skip to content

Commit e4f34ec

Browse files
committed
Enhancing... Color echo and code cleanups
1 parent 59f0602 commit e4f34ec

1 file changed

Lines changed: 27 additions & 18 deletions

File tree

commit

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,35 @@
11
#!/usr/bin/env bash
2+
set -euo pipefail
23

3-
echo 'Running commit script'
4-
5-
IGNORED_BRANCHES=("dev" "master" "qa" "uat" "staging")
4+
IS_IGNORED=false
65
IGNORED_PATH="./.ignore"
6+
CURRENT_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
7+
IGNORED_BRANCHES=("dev" "master" "qa" "uat" "staging")
8+
9+
colorEcho(){
10+
RED="\033[0;31m"
11+
GREEN='\033[0;32m'
12+
YELLOW='\033[1;33m'
13+
NO_COLOR='\033[0m'
14+
printf "${!1}${2} ${NO_COLOR}\n"
15+
}
716

8-
if [ -f "$IGNORED_PATH" ]
17+
commitWithBranch() {
18+
colorEcho "GREEN" "Commit translation: \"$CURRENT_BRANCH: $1\""
19+
git commit -m "$CURRENT_BRANCH: $1"
20+
}
21+
22+
if [[ -f "$IGNORED_PATH" ]]
923
then
1024
CUSTOM_BRANCHES=$(cat "$IGNORED_PATH")
1125
BRANCHES=( $CUSTOM_BRANCHES )
1226
IGNORED_BRANCHES=( ${IGNORED_BRANCHES[@]} ${BRANCHES[@]} )
13-
fi
14-
15-
CURRENT_BRANCH_CMD="git rev-parse --abbrev-ref HEAD"
16-
CURRENT_BRANCH=$(eval $CURRENT_BRANCH_CMD)
17-
18-
COMMIT_WITH_BRANCH="git commit -m \"$CURRENT_BRANCH: $1\""
19-
DEFAULT_COMMIT="git commit -m \"$1\""
27+
colorEcho "YELLOW" ".ignore file found. Skimming off from .ignore file"
28+
else
29+
colorEcho "YELLOW" ".ignore file not found"
30+
fi
2031

21-
IS_IGNORED=false
22-
23-
for branch in "${IGNORED_BRANCHES[@]}";
32+
for branch in "${IGNORED_BRANCHES[@]}"
2433
do
2534
if [ "$CURRENT_BRANCH" == $branch ]
2635
then
@@ -29,11 +38,11 @@ for branch in "${IGNORED_BRANCHES[@]}";
2938
fi
3039
done
3140

41+
3242
if [ "$IS_IGNORED" == false ]
3343
then
34-
echo "Commiting with branch name -> $CURRENT_BRANCH"
35-
eval $COMMIT_WITH_BRANCH
44+
commitWithBranch $1
3645
else
37-
echo "Commiting with default branch"
38-
eval $DEFAULT_COMMIT
46+
colorEcho "GREEN" "Commit translation: \"$1\""
47+
git commit -m "$1"
3948
fi

0 commit comments

Comments
 (0)