Skip to content

Commit 558cbed

Browse files
author
Guillaume LODI
committed
Added file utils
1 parent 9c6426e commit 558cbed

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lemin/lemin.sh

+4-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ generatemap () {
5959
for f in {1..30}
6060
do
6161
printf "${C_GRY}.${C_RES}"
62-
./$BASE/generator "$2" > "$BASE/maps/$1$(printf '%02d' $f)"
62+
$BASE/generator "$2" > "$BASE/maps/$1$(printf '%02d' $f)"
6363
sleep 1
6464
done
6565
}
@@ -76,6 +76,9 @@ runtest () {
7676
}
7777

7878
#############################
79+
fileexist "$PROJECT_PATH/lem-in"
80+
fileisexecutable "$PROJECT_PATH/lem-in"
81+
7982
generate=1
8083
if [ -d "$BASE/maps" ]; then
8184
read -p "Would you like to generate new maps [y/N]? " -n 1 -r

utils/func.sh

+25
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/bin/bash
22

3+
##
4+
# Print
5+
##
36
printtest () {
47
printf "${C_CYA}${C_UND}\nTest:${C_RESU} ${1}${C_RES}\n"
58
}
@@ -13,7 +16,29 @@ printerror () {
1316
}
1417

1518

19+
##
20+
# Others
21+
##
1622
waitkeypress () {
1723
printf "${C_GRY}Press enter to continue...${C_RES} "
1824
read
1925
}
26+
27+
##
28+
# File tests
29+
##
30+
31+
fileexist () {
32+
if ! [ -f "$1" ]; then
33+
printerror "File $1 does not exist."
34+
exit 1
35+
fi
36+
}
37+
38+
fileisexecutable () {
39+
if ! [ -x "$1" ]; then
40+
printerror "File $1 is not executable."
41+
printinfo "You can try to run 'chmod u+x $1' to fix this"
42+
exit 1
43+
fi
44+
}

0 commit comments

Comments
 (0)