-
Notifications
You must be signed in to change notification settings - Fork 0
/
gmtcn.sh
executable file
·181 lines (159 loc) · 4.08 KB
/
gmtcn.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/bin/bash
function usage () {
cat <<-EOF >&2
gmtcn - Show Chinese HTML documentation of GMT's specified module.
GMT 中文社区 (https://gmt-china.org/)
Usage:
gmtcn docs home
gmtcn docs <module-name>
gmtcn docs <option-name>
gmtcn docs <proj-name>
gmtcn docs <setting-name>
gmtcn docs <other>
Module-name:
All translated GMT module
Option-name:
-B -R -J -x -a -: ...
Proj-name:
-JP -JX -JQ ...
Setting-name:
FONT MAP COLOR DIR FORMAT IO PROJ PS TIME OTHER
Other:
module option proj setting gallery
install started advanced
table grid cpt dataset chinese api
canvas unit color pen fill font char latex vector line anchor panel dir
EOF
exit
}
# usage
if [ $# -eq 0 ]; then
usage
fi
# Arguments check
if [ ${1} != "docs" ]; then
echo -e "\n\033[31m ERROR: ${1} is not recognized or supprted. \033[0m"
usage
fi
if [ ! -n "${2}" ]; then
usage
fi
# system
sys=$(uname)
if [ ${sys} = "Linux" ] ; then
open=xdg-open
${open} --version > /dev/null || echo -e "\n\033[31m ERROR: ${open} does not exist. \033[0m"
elif [ ${sys} = "Darwin" ] ; then
open=open
elif [ ${sys} = *MINGW64* ] ; then
open=start
else
echo -e "\n\033[31m ERROR: ${sys} is not recognized or supported. \033[0m"
exit
fi
baseurl=https://docs.gmt-china.org/latest
J=""
opt=""
case $2
in
home)
${open} ${baseurl}
exit
;;
module|option|proj|conf|install|table|grid|cpt|dataset|chinese|api)
${open} "${baseurl}/${2}"
exit
;;
setting)
${open} "${baseurl}/conf"
exit
;;
gallery)
${open} "${baseurl}/gallery"
exit
;;
started|advanced)
${open} "${baseurl}/tutorial/${2}"
exit
;;
-J)
opt=$2
;;
-J*)
J=$2
;;
-*)
opt=$2
;;
*)
;;
esac
option=(-B -J -R -U -V -X -Y -a -b -c -d -e -f -g -h -i -j -l -n -o -p -q -r -s -t -w -x -:)
option_parse=(B J R U V XY XY a binary c d e f g h io distcal l n io p q nodereg s t w x colon)
if [ ! x"$opt" = x ]; then
for i in ${!option[@]}
do
if [ ${opt} = ${option[$i]} ]; then
${open} "${baseurl}/option/${option_parse[$i]}"
exit
else
if [ $(($i+1)) -eq ${#option[@]} ]; then
echo -e "\n\033[31m ERROR: No option named ${2} is found. \033[0m"
usage
fi
fi
done
fi
proj=(-JX -JP -JA -JB -JC -JCyl_stere -JD -JE -JF -JG -JH -JI -JJ -JK -JL -JM -JN -JO -JPoly -JQ -JR -JS -JT -JU -JV -JW -JY)
proj_parse=(Jx Jp Ja Jb Jc Jcyl_stere Jd Je Jf Jg Jh Ji Jj Jk Jl Jm Jn Jo Jpoly Jq Jr Js Jt Ju Jv Jw Jy)
if [ ! x"$J" = x ]; then
for i in ${!proj[@]}
do
if [ ${J} = ${proj[$i]} ]; then
${open} "${baseurl}/proj/${proj_parse[$i]}"
exit
else
if [ $(($i+1)) -eq ${#proj[@]} ]; then
echo -e "\n\033[31m ERROR: No projection named ${2} is found. \033[0m"
usage
fi
fi
done
fi
# basic
basic=( canvas unit color pen fill font char latex arrow line anchor panel dir )
basic_parse=(canvas unit color pen fill text special-character latex vector line anchor embellishment input-files)
for i in ${!basic[@]}
do
if [ ${2} = ${basic[$i]} ]; then
${open} "${baseurl}/basis/${basic_parse[$i]}"
exit
fi
done
# setting
setting=(FONT MAP COLOR DIR FORMAT IO PROJ PS TIME OTHER)
setting_parse=(font map color dir format io proj ps time misc)
for i in ${!setting[@]}
do
if [ ${2} = ${setting[$i]} ]; then
${open} "${baseurl}/conf/${setting_parse[$i]}"
exit
fi
done
# module
module=( `gmt --show-modules ` )
for i in ${!module[@]}
do
if [ ${2} = ${module[$i]} ]; then
${open} "${baseurl}/module/${2}"
exit
elif [ "gmt${2}" = ${module[$i]} ]; then
${open} "${baseurl}/module/gmt${2}"
exit
else
if [ $(($i+1)) -eq ${#module[@]} ]; then
echo -e "\n\033[31m ERROR: No model named ${2} is found. \033[0m"
usage
fi
fi
done