-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheat.sh
executable file
·74 lines (68 loc) · 1.15 KB
/
cheat.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
#!/bin/bash
# Author https://github.com/grigruss
# Check translate-shell script
if ! trans -V >/dev/null
then
echo -e "\\n\\e[33mWARNING!\\n========\\e[0m"
echo -e "To run the script, you need a 'trans' script from this repository:"
echo -e "https://github.com/soimort/translate-shell/releases\\n"
exit 1
fi
# Check curl
if ! curl -V >/dev/null
then
echo -e "\\n\\e[33mWARNING!\\n========\\e[0m"
echo -e "To run the script, you need install 'curl'"
exit 1
fi
lang=$(locale | grep -i lang)
lang="${lang:5:2}"
T=0
while [ -n "$1" ]
do
case "$1" in
-T) T=1;;
*) U="$1"; break;;
esac
shift
done
src=$(curl "cht.sh/${U}?T" 2>/dev/null)
IFS=$'\n'
S=''
for answ in $src
do
if [[ "${answ:0:1}" == "#" ]]
then
S+="
$answ"
fi
done
res=$(trans -b "$S")
R=''
C=0
IFS=$'\n'
for row in $res
do
R[$C]="$row"
((C++))
done
count=0
IFS=$'\n'
for answ in $src
do
if [[ "${answ:0:1}" == "#" ]]
then
VR="${R[$count]//#/# \[$lang\]}"
VE="${answ//#/# \[en\]}"
if [[ "$T" == 0 ]]
then
echo -e "\e[32;1m$VR\e[0m\n\e[30;1m$VE\e[0m"
else
echo -e "$VR\n$VE"
fi
((count++))
else
echo "$answ"
echo
fi
done