-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_repo_company_name.sh
executable file
·67 lines (60 loc) · 2.09 KB
/
get_repo_company_name.sh
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
62
63
64
65
66
67
#!/bin/bash
repo_full_name=$1
# SrgAppCisampleAndroid --> srg-app-cisample-android
mapStringFromUpperCaseFormatToDashLowerCaseFormat() {
stringBuilder=""
pluginName="$1"
DELIMITER_DASH="-"
# for loop all the characters in a string
while read -n1 character; do
# check if the character is uppercase
if [[ "$character" =~ [A-Z] ]]; then
#convert a character/string from upper case to lower case
character_in_lowercase=$(echo -e "${character}" | tr '[:upper:]' '[:lower:]')
# check if stringBuilder is not empty
if [ -n "${stringBuilder}" ]; then
stringBuilder="${stringBuilder}${DELIMITER_DASH}${character_in_lowercase}"
else
stringBuilder="${character_in_lowercase}"
fi
else
stringBuilder="${stringBuilder}$character"
fi
done <<< "${pluginName}"
# for ((i = 0; i <= ${#pluginName}; i++)); do
# character="${pluginName:$i:1}"
# # check if the character is uppercase
# if [[ "$character" =~ [A-Z] ]]; then
# #convert a character/string from upper case to lower case
# character_in_lowercase=$(echo -e "${character}" | tr '[:upper:]' '[:lower:]')
# # check if stringBuilder is not empty
# if [ -n "${stringBuilder}" ]; then
# stringBuilder="${stringBuilder}${DELIMITER_DASH}${character_in_lowercase}"
# else
# stringBuilder="${character_in_lowercase}"
# fi
# else
# stringBuilder="${stringBuilder}$character"
# fi
# done
echo "${stringBuilder}"
}
#srg-app-cisample-android --> srg
getRepoCompanyName() {
dashFormatString="$1"
DELIMITER_DASH="-"
a_company_name=$(echo "${dashFormatString}" | cut -d "${DELIMITER_DASH}" -f1)
echo "${a_company_name}"
}
# SrgAppCisampleAndroid --> srg
getRepoCompanyNameFromRepoName() {
dash_repo_name=$(mapStringFromUpperCaseFormatToDashLowerCaseFormat "$1")
a_company_name=$(getRepoCompanyName "${dash_repo_name}")
echo "${a_company_name}"
}
if [[ -z "${repo_full_name}" ]]; then
exit 1
else
repo_company_name_lower_case=$(getRepoCompanyNameFromRepoName "${repo_full_name}")
echo "${repo_company_name_lower_case}"
fi