-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdtssview.sh
More file actions
executable file
·76 lines (68 loc) · 2.09 KB
/
Copy pathdtssview.sh
File metadata and controls
executable file
·76 lines (68 loc) · 2.09 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
#!/bin/bash
function getLine() {
line=$1
file=$2
# https://community.unix.com/t/extract-a-line-from-a-file-using-the-line-number/163887/3
echo $(sed $line!d "$file")
}
function getItemProperty() {
line=$1
file=$2
echo $(getLine $line "$file" | cut -f2- -d:)
}
function readScript() {
scriptFile="$1"
if ! [ -f "$scriptFile" ]; then
# The file does not exist.
return
fi
# The starter script header contains 4 lines:
# - Language
# - Name
# - Description
# - Customizable?
# Windows likes to use CRLF, which is not nice for the UNIX parser; get rid
# of the carriage returns
dtssLang=$(getItemProperty 1 "$1" | tr -d " " | tr -d '\r')
dtssName=$(getItemProperty 2 "$1" | sed 's/^[[:space:]]*//' | tr -d '\r')
dtssDesc=$(getItemProperty 3 "$1" | sed 's/^[[:space:]]*//' | tr -d '\r')
dtssCust=$(getItemProperty 4 "$1" | cut -f2 -d? | tr -d " " | tr -d '\r')
if [[ "$dtssCust" == "Yes" ]]; then
dtssCust=true
else
dtssCust=false
fi
echo -e " {"
echo -e " \"language\": \"$dtssLang\","
echo -e " \"name\": \"$dtssName\","
echo -e " \"description\": \"$dtssDesc\","
echo -e " \"customizable\": $dtssCust,"
echo -e " \"fileName\": \"$(basename "$scriptFile")\""
echo -en " }"
}
if [ $# -lt 1 ]; then
echo "Please provide one or more starter scripts to process and try again. Press any"
echo "key to exit . . ."
read -sn1
else
# Begin writing the JSON
echo -e "{\n \"scripts\": ["
for dtss in "$*"; do
if [ -d "$dtss" ]; then
# Get file count to determine when to stop appending commas
lines=$(ls -lA "$dtss"/*.dtss | wc -l)
fileIdx=0
for file in "$dtss"/*.dtss; do
readScript "$file"
fileIdx=$(($fileIdx+1))
if [ $fileIdx -lt $lines ]; then
echo -n ","
fi
echo -en "\n"
done
else
readScript "$dtss"
fi
done
echo -e " ]\n}"
fi