-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyro.sh
executable file
·67 lines (49 loc) · 1.21 KB
/
pyro.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
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
# file locations
if [ -z "$PYRO_REGEX" ]; then
PYRO_REGEX=~/.config/pyro/pyro.regex
fi
if [ -z "$PYRO_CONFIG" ]; then
PYRO_CONFIG=.pyro
fi
# define delimiter
IFS=': '
PYFILE="$1.py"
PYROFILE="$1.pyro"
# fancy print: "Transpiling [filename.pyro]."
tput setaf 3 && echo -n "Transpiling "
tput setaf 6 && echo -n "$PYROFILE"
tput setaf 3 && echo "."
# copy the file to .py
if test -f $PYFILE; then
rm $PYFILE
fi
cp $PYROFILE $PYFILE
# print details header
if [[ $* == *-d* ]]; then
echo "Replacing..."
fi
# go through every line in the .pyro file
cat $PYRO_CONFIG | while read line; do
# check if line is empty
if [ ! -z "$line" ]; then
# separate into key/value
read key val <<< "$line"
if [[ $* == *-d* ]]; then # print details
tput setaf 6 && echo -ne " $val"
tput setaf 3 && echo -n " > "
tput setaf 6 && echo $key
tput setaf 3
fi
# go through every line in the [name].pyro file
# if theres a match, then replace
regex=$($PYRO_REGEX $key $val)
sed -E -i "" "$regex" $PYFILE
fi
done
# run the file
if [[ $* != *-c* ]]; then
echo "Running..."
tput setab 0 && tput setaf 7 && echo "> python $PYFILE" && tput setaf 9
python $PYFILE $2
fi