-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
whatsapp.sh
executable file
·120 lines (98 loc) · 2.63 KB
/
whatsapp.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env sh
## Dark-WhatsApp helper script. \n
##
## \033[0;36mUsage:\033[0m
## sh whatsapp.sh [-cufprh] \n
##
## \033[0;36mOptions:\033[0m
## -c Compile custom ~wa.user.styl~ userstyle.
## -u Compile ~wa.user.styl~ to ~wa.user.css~.
## -f Convert ~wa.user.css~ to ~darkmode.css~.
## -p Print the file content to standard output.
## -r Remove files generated by this script.
## -h Print help and exit. \n
##
## Source:
## \033[0;34m https://github.com/vednoc/dark-whatsapp \033[0m \n
##
## Documentation:
## \033[0;34m https://github.com/vednoc/dark-whatsapp/wiki \033[0m
short_help() {
help | tail -n +2
}
help() {
printf "$(sed -n "s/##\ //p" "$0") \n"
}
print() {
if [ -n "${USERCSS+x}" ]; then
input="wa.user.css"
elif [ -n "${COMPILE+x}" ]; then
input="custom.user.css"
else
echo "You must pick an option." >&2
exit 0
fi
cat $input
}
remove_if_exists() {
if [ -f "$1" ]; then
rm "$1"
fi
}
remove() {
echo "Removing files..."
remove_if_exists temp.styl
remove_if_exists darkmode.css
remove_if_exists custom.user.css
echo "Done!"
}
compile() {
echo "Compiling..."
temp="temp.styl"
input="wa.user.styl"
if [ -n "${USERCSS+x}" ]; then
output="wa.user.css"
else
output="custom.user.css"
fi
sed -n '/^\/\//,$p; 1i @import("metadata.styl");' $input > $temp
if command -v stylus >/dev/null; then
stylus $temp -o $output
rm $temp
elif ! command -v npm >/dev/null; then
echo "You're missing ~npm~ and ~Node.js~ libraries." >&2
else
echo "Missing ~stylus~ executable in your \$PATH." >&2
fi
}
convert() {
echo "Converting..."
if [ -n "${USERCSS+x}" ]; then
input="wa.user.css"
elif [ -n "${COMPILE+x}" ]; then
input="custom.user.css"
else
input="wa.user.css"
fi
output="darkmode.css"
sed -n '/:root/,$p' $input | sed 's/^\ \ //; $d' > $output
[ -e $output ] && echo "Done! $output is ready." \
|| echo "File not found!" >&2
}
[ $# -eq 0 ] && { echo "No arguments given"; short_help; }
while getopts "rcfuph" option; do
case "$option" in
"r") REMOVE=1 ;;
"c") COMPILE=1 ;;
"f") CONVERT=1 ;;
"u") USERCSS=1 ;;
"p") PRINT=1 ;;
"h") help ;;
*) short_help ;;
esac
done
# Functions need to run in this order, therefore they are not called in getopts.
[ -n "${REMOVE+x}" ] && remove
[ -n "${COMPILE+x}" ] && compile
[ -n "${CONVERT+x}" ] && convert
[ -n "${PRINT+x}" ] && print