forked from samiuljoy/quran
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuran
172 lines (147 loc) · 4.88 KB
/
Quran
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
#!/usr/bin/env sh
# check if $HOME/.local/share/ exists
if [ -f "$HOME/.local/share/Quran/Quran.txt" ]; then
file_dir="$HOME/.local/share/Quran/Quran.txt"
elif [ -f "Quran.txt" ]; then
file_dir="Quran.txt"
else
echo "file Quran.txt file not found" && \
return 1
fi
# functions begin
# variable names
usage() {
echo
echo "Usage:"
echo "-l or --list = List of Sura"
echo "-s or --search = Search for a keyword"
echo "-eg or --example = print out some examples"
echo "-h or --help = print out this help message"
echo "Example: Quran -h"
exit
}
# Different examples
example() {
echo
echo "Quran kahf = Will print out the complete Sura Kahf"
echo "Quran 18 = Will print out the 18th Sura in The Holy Quran"
echo "Quran kahf:10 = Will print out the 10th verse of Sura Kahf"
echo "Quran 18:10 = Will print out the 10th verse of 18th Sura in The Holy Quran"
echo "Quran kahf:1-10 = Will print out the verse 1 to 10 of Sura kahf"
echo "Quran 18:1-10 = Will print out the 1 to 10 verse of the 18th Sura in The Holy Quran"
echo "Quran falaq-naas = Will print out Sura Falaq to Sura Naas"
echo "Quran 113-114 = Will print out the 113th to 114th Sura in The Holy Quran"
echo
}
# Loop through verses
verse_loop() {
echo "With The Name Of Allah, The Most Merciful, The Most Gracious" >> sura.txt
while [ "$from" -le "$to" ]; do
grep "\[$chapter:$from\]" $file_dir | \
sed 's/^\[.*:\(.*\)\]\s\(.*\)/\n\n[\1] \2/g' >> sura.txt
from="$(( $from + 1 ))"
done
}
# Loop through chapters
chapter_loop() {
while [ "$schapter" -le "$echapter" ]; do
grep -w3 "\[$schapter:*" $file_dir | \
sed 's/^\[\(.*\)\]\s\(.*\)/\n\n[\1] \2/g' >> sura.txt
schapter="$(( $schapter + 1 ))"
done
}
# opening grace message
opening_msg() {
echo "With the name of Allah, The Most Merciful. The Most Gracious" >> sura.txt
echo " " >> sura.txt
}
# functions end
# case statements
case "$1" in
""|" " ) # print usage message if first argument is empty
usage
;;
-s|--search ) # search parameter/argument
# if search keyword is empty, exit with exit status 1
[ -z "$2" ] && \
echo "empty search keyword" && \
return 1
# if search keyword is non-empty
grep -i "$2" $file_dir | \
sed 's/^\[\(.*\)\]\s\(.*\)/\n\n[\1] \2/g' | less
;;
-h|--help ) # prints help message/usage
usage
;;
-eg|--example ) # shows examples
example
;;
-l|--list ) # shows list of suras from the index
sed -n '1,117p' $file_dir | less
;;
* ) break
;;
esac
# Digit interpretation
# General
echo $1 | grep -q "^[[:digit:]]\+$"
[ "$?" = 0 ] && \
grep -w3 "^\[$1:*" $file_dir | \
sed 's/^\[.*:\(.*\)\]\s\(.*\)/\n\n[\1] \2/g' | \
less && [ -f sura.txt ] && rm sura.txt
# Show verse
echo $1 | grep -q "^[[:digit:]]\+:[[:digit:]]\+$"
[ "$?" = 0 ] && echo "$1" | sed 's/\(.*\):.*/\1/g' | \
xargs -I '{}' grep -m1 "^{}\.\s" $file_dir> sura.txt && \
opening_msg && \
grep "\[$1\]" $file_dir>> sura.txt && \
less sura.txt && rm sura.txt
# Verse range
echo $1 | grep -q "^[[:digit:]]\+:[[:digit:]]\+-[[:digit:]]\+$"
[ "$?" = 0 ] && \
chapter="$(echo $1 | cut -d ':' -f1)" && \
from="$(echo $1 | sed 's/.*:\(.*\)-.*/\1/g')" && \
to="$(echo $1 | sed 's/.*-\(.*\)/\1/g')" && \
grep -m1 "^$chapter\.\s" $file_dir> sura.txt && \
verse_loop && less sura.txt && rm sura.txt
# chapter range
echo $1 | grep "^[[:digit:]]\+-[[:digit:]]\+$" | grep -q -v ":"
[ "$?" = 0 ] && \
schapter="$(echo $1 | cut -d '-' -f1)" && \
echapter="$(echo $1 | cut -d '-' -f2)" && \
chapter_loop && less sura.txt && rm sura.txt
# Alphabetical interpretation
# General
echo $1 | grep -q "^[[:alpha:]]\+$"
[ "$?" = 0 ] && \
achapter="$(grep -i -m1 "$1" $file_dir | cut -d '.' -f1)" && \
grep -w3 "^\[$achapter:*" $file_dir | \
sed 's/^\[.*:\(.*\)\]\s\(.*\)/\n\n[\1] \2/g' | \
less && [ -f sura.txt ] && rm sura.txt
# Show verse
echo $1 | grep -q "^[[:alpha:]]\+:[[:digit:]]\+$"
[ "$?" = 0 ] && \
verse="$(echo $1 | cut -d ':' -f2)" && \
chapter="$(echo $1 | cut -d ':' -f1 | \
xargs -I '{}' grep -i -m1 "{}" $file_dir | cut -d '.' -f1)" && \
grep -i -m1 "^$chapter\.\s" $file_dir> sura.txt && \
opening_msg && \
grep "\[$chapter:$verse\]" $file_dir>> sura.txt && \
less sura.txt && rm sura.txt
# Verse range
echo $1 | grep -q "^[[:alpha:]]\+:[[:digit:]]\+-[[:digit:]]\+$"
[ "$?" = 0 ] && \
chapter="$(echo $1 | cut -d ':' -f1 | \
xargs -I '{}' grep -i -m1 "{}" $file_dir | cut -d '.' -f1)" && \
from="$(echo $1 | sed 's/.*:\(.*\)-.*/\1/g')" && \
to="$(echo $1 | sed 's/.*-\(.*\)/\1/g')" && \
grep -i -m1 "^$chapter\.\s" $file_dir> sura.txt && \
verse_loop && less sura.txt && rm sura.txt
# chapter range
echo $1 | grep -q "^[[:alpha:]]\+-[[:alpha:]]\+$"
[ "$?" = 0 ] && \
schapter="$(echo $1 | cut -d '-' -f1 | \
xargs -I '{}' grep -i -m1 "{}" $file_dir | cut -d '.' -f1)" && \
echapter="$(echo $1 | cut -d '-' -f2 | \
xargs -I '{}' grep -i -m1 "{}" $file_dir | cut -d '.' -f1)" && \
chapter_loop && less sura.txt && rm sura.txt