forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shellUtils.sh
43 lines (36 loc) · 827 Bytes
/
shellUtils.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
#!/bin/bash
declare -r GREEN=$'\e[1;32m'
declare -r RED=$'\e[1;31m'
declare -r BLUE=$'\e[1;34m'
declare -r TITLE=$'\e[1;4;34m'
declare -r RESET=$'\e[0m'
function success {
echo "🎉 $GREEN$1$RESET"
}
function error {
echo "💥 $RED$1$RESET"
}
function info {
echo "$BLUE$1$RESET"
}
function title {
printf "\n%s%s%s\n" "$TITLE" "$1" "$RESET"
}
function assert_equal {
if [[ "$1" != "$2" ]]; then
error "Assertion failed: $1 is not equal to $2"
exit 1
else
success "Assertion passed: $1 is equal to $1"
fi
}
# Usage: join_by_string <delimiter> ...strings
# example: join_by_string ' + ' 'string 1' 'string 2'
# example: join_by_string ',' "${ARRAY_OF_STRINGS[@]}"
function join_by_string {
local separator="$1"
shift
local first="$1"
shift
printf "%s" "$first" "${@/#/$separator}"
}