-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.bash
More file actions
99 lines (92 loc) · 1.85 KB
/
Copy pathstring.bash
File metadata and controls
99 lines (92 loc) · 1.85 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
function to_true()
{
local val="${1}"
local trues=('true' 't' 'yes' 'y' 'on' '1')
for t in ${trues[@]}; do
if [ "${t}" == "${val}" ]; then
echo 'true'
return 0
fi
done
echo 'false'
}
function to_false()
{
local val="${1}"
local trues=('false' 'f' 'no' 'n' 'off' '0')
for t in ${trues[@]}; do
if [ "${t}" == "${val}" ]; then
echo 'false'
return 0
fi
done
echo 'true'
}
function is_number()
{
local str="${1}"
if [ "${str}" -ge 0 ] 2>/dev/null; then
echo 'true'
else
if [ "${str}" -lt 0 ] 2>/dev/null; then
echo 'true'
else
echo 'false'
fi
fi
}
function lines_to_list()
{
local lines="${1}"
readarray -t ARRAY <<< "${lines}"; IFS=','; echo "${ARRAY[*]}"
}
function list_to_array()
{
local list="${1}"
echo "${list}" | tr ',' "\n"
}
function normalize_github_addr()
{
local addr="${1}"
local addr_check=`echo "${addr}" | { grep 'http' || test $? = 1; }`
if [ ! -z "${addr_check}" ]; then
echo "${addr}"
return 0
fi
local addr_check=`echo "${addr}" | { grep '@' || test $? = 1; }`
if [ ! -z "${addr_check}" ]; then
echo "${addr}"
return 0
fi
echo "https://github.com/${addr}"
}
function extract_lines_section()
{
local lines="${1}"
local section="${2}"
local next_sect=''
if [ ! -z "${3+x}" ]; then
local next_sect="${3}"
fi
local lines=`echo "${lines}" |\
{ grep -A 999999 "${section}" || test $? = 1; } |\
{ grep -v "${section}" || test $? = 1; } |\
{ grep -v '\-\-\-\-' || test $? = 1; }`
if [ ! -z "${next_sect}" ]; then
local lines=`echo "${lines}" |\
{ grep -B 999999 "${next_sect}" || test $? = 1; } |\
{ grep -v "${next_sect}" || test $? = 1; }`
fi
echo "${lines}"
}
function match_lines_cnt()
{
local lines="${1}"
local target="${2}"
local filtered=`echo "${lines}" | { grep "${target}" || test $? = 1; }`
if [ -z "${filtered}" ]; then
echo '0'
else
echo "${filtered}" | wc -l
fi
}