-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
helper.sh
50 lines (42 loc) · 845 Bytes
/
helper.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
# shellcheck shell=sh
pass_fail_number=0
abort() {
printf '\033[31m[ERROR]\033[m %s\n' "$*"
exit 1
}
fail() {
msg=$1 pass_fail_number=$((pass_fail_number+1))
shift
case $# in
0) set -- "$pass_fail_number" ;;
*) set -- "$pass_fail_number" "$@" ;;
esac
# shellcheck disable=SC2059
printf "%3d \033[31m[fail]\033[m $msg\n" "$@"
}
pass() {
msg=$1 pass_fail_number=$((pass_fail_number+1))
shift
case $# in
0) set -- "$pass_fail_number" ;;
*) set -- "$pass_fail_number" "$@" ;;
esac
# shellcheck disable=SC2059
printf "%3d \033[32m[pass]\033[m $msg\n" "$@"
}
run() {
echo '$' "$@"
"$@"
}
make_dir() {
run mkdir -p "$1"
}
make_file() {
mkdir -p "$(dirname "$1")"
run touch "$1"
}
make_link() {
from=${1#*" -> "} to=${1%" -> "*}
mkdir -p "$(dirname "$to")"
run ln -snf "$from" "$to"
}