Friday, December 27, 2019

Membuka (terjemah) Quran di Terminal

Hari ini saya iseng mencari-cari aplikasi yang bisa menampilkan Al-Quran di command line alias terminal. Apa manfaatnya? (1) Ketika disebutkan surat dan ayatnya, misal 7:37, kita segera tahu arti ayat tersebut (dalam bahasa inggris); (2) Ketika membaca Quran (yang tidak ada terjemahannya), kita juga bisa langsung tahu artinya. Ternyata ada aplikasi ini Github. Langsung cus saya coba. Berikut tutorial singkatnya.


Instalasi

Nama aplikasinya "wahy", instalasinya dengan menggunakan "gem" (The ruby package manager).
Untuk menginstall cukup dengan,
bta@g580:~$ sudo gem install wahy
[sudo] password for bagustris: 
Fetching: colorize-0.8.1.gem (100%)
Successfully installed colorize-0.8.1
Fetching: mini_portile2-2.4.0.gem (100%)
Successfully installed mini_portile2-2.4.0
Fetching: nokogiri-1.10.7.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing wahy:
 ERROR: Failed to build gem native extension.

    current directory: /var/lib/gems/2.3.0/gems/nokogiri-1.10.7/ext/nokogiri
/usr/bin/ruby2.3 -r ./siteconf20191227-6665-bseemh.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.3.0/gems/nokogiri-1.10.7 for inspection.
Results logged to /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/nokogiri-1.10.7/gem_make.out

Hidup memang tidak selalu mulus. Pada perintah di atas terdapat error, padahal saya install sebelumnya di laptop saya yang lain, sama-sama Ubuntu 16.04 tidak ada masalah. Googling sebentar, akhirnya saya menemukan solusinya seperti berikut. Kata kunci pencarian: " ERROR: Failed to build gem native extension."

bta@g580:~$ sudo apt install ruby-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  ruby2.3-dev
The following NEW packages will be installed:
  ruby-dev ruby2.3-dev
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,038 kB of archives.
After this operation, 4,821 kB of additional disk space will be used.
Do you want to continue? [Y/n] y

Saya lanjutkan dengan instalasi "wahy" lagi,
bta@g580:~$ sudo gem install wahy
Building native extensions.  This could take a while...
Successfully installed nokogiri-1.10.7
Fetching: wahy-1.3.6.gem (100%)
Successfully installed wahy-1.3.6
Parsing documentation for nokogiri-1.10.7
Installing ri documentation for nokogiri-1.10.7
Parsing documentation for wahy-1.3.6
Installing ri documentation for wahy-1.3.6
Done installing documentation for nokogiri, wahy after 5 seconds
2 gems installed

Berhasil!

Penggunaan

Untuk mengetahui cara menggunakan "wahy", ketikkan help-nya,

bta@g580:~$ wahy -h
Usage: wahy [options]
    -l, --lang=LANGUAGE              Which language that you want to read signs?
    -s, --scripture=SCRIPTURE        Scripture name or number
    -a, --ayah=SIGN                  Sign number
    -h, --help                       Prints this help

Jadi "argumen"nya adalah "bahasa", "surat", dan "ayat".
Misalnya ingin membuka Quran surat 1 ayat 1 (-s 1 -a 1),
dengan bahasa Inggris (-l en), sementara hanya mendukung bahasa Inggris dan Turki. Jika tanpa argumen ayat, wahy akan menampilkan isi semua ayat surat tersebut. Begitu halnya jika tanpa argumen sama sekali (hanya "wahy" saja), semua ayat surat pertama akan ditampilkan.

Contoh:
bta@g580:~$ wahy -l en -s 1 -a 1
**************THE OPENING***************
[1]: In the name of Allah, Most Gracious, Most Merciful.

Jika ingin menampilkan semuat ayat dalam suratnya, kosongkan opsi/argumen ayat.

bta@g580:~$ wahy -l en -s 1
**************THE OPENING***************
[1]: In the name of Allah, Most Gracious, Most Merciful.
[2]: Praise be to Allah, the Cherisher and Sustainer of the worlds;
[3]: Most Gracious, Most Merciful;
[4]: Master of the Day of Judgment.
[5]: Thee do we worship, and Thine aid we seek.
[6]: Show us the straight way,
[7]: The way of those on whom Thou hast bestowed Thy Grace, those whose (portion) is not wrath, and who go not astray.

Cukup simpel meski terbatas. Bahasa Indonesia belum didukung, dan opsi ayat berupa range (misal 2-4) juga belum didukung. Lalu bagaimana kalau kita ingin range ayat, bukan satu ayat? "sed" adalah jawabanya. Output dari "wahy" kita piping ke "sed".

Contoh kita ingin mencari terjemah Al-Baqoroh ayat 183-185. Karena output dari "wahy" ada tambahan nama suratnya di baring paling atas, maka nomor ayatnya kita tambah satu, jadi yang kita cari baris 185-186.

bta@g580:~$ wahy -s 2 | sed -n '184,186p'
[183]: O ye who believe! Fasting is prescribed to you as it was prescribed to those before you, that ye may (learn) self-restraint,-
[184]: (Fasting) for a fixed number of days; but if any of you is ill, or on a journey, the prescribed number (Should be made up) from days later. For those who can do it (With hardship), is a ransom, the feeding of one that is indigent. But he that will give more, of his own free will,- it is better for him. And it is better for you that ye fast, if ye only knew.
[185]: Ramadhan is the (month) in which was sent down the Qur´an, as a guide to mankind, also clear (Signs) for guidance and judgment (Between right and wrong). So every one of you who is present (at his home) during that month should spend it in fasting, but if any one is ill, or on a journey, the prescribed period (Should be made up) by days later. Allah intends every facility for you; He does not want to put to difficulties. (He wants you) to complete the prescribed period, and to glorify Him in that He has guided you; and perchance ye shall be grateful.

Berhasil! Muncul terjemah Al-Baqoroh 183-185. Opsi -n untuk --silent, p untuk print (print baris 184-186). Selanjutnya, bagaimana bila kita ingin menampilkan sekuen ayat, misal ayat 35, kemudian ayat 183-185, dan 200-203. Kita gunakan opsi "-e" (execute script). Ingat nomor barisnya kita tambah satu dari nomor ayat.

bta@g580:~$ wahy -s 2 | sed -n -e 36p -e 184,186p -e 201,204p
[35]: We said: "O Adam! dwell thou and thy wife in the Garden; and eat of the bountiful things therein as (where and when) ye will; but approach not this tree, or ye run into harm and transgression."
[183]: O ye who believe! Fasting is prescribed to you as it was prescribed to those before you, that ye may (learn) self-restraint,-
[184]: (Fasting) for a fixed number of days; but if any of you is ill, or on a journey, the prescribed number (Should be made up) from days later. For those who can do it (With hardship), is a ransom, the feeding of one that is indigent. But he that will give more, of his own free will,- it is better for him. And it is better for you that ye fast, if ye only knew.
[185]: Ramadhan is the (month) in which was sent down the Qur´an, as a guide to mankind, also clear (Signs) for guidance and judgment (Between right and wrong). So every one of you who is present (at his home) during that month should spend it in fasting, but if any one is ill, or on a journey, the prescribed period (Should be made up) by days later. Allah intends every facility for you; He does not want to put to difficulties. (He wants you) to complete the prescribed period, and to glorify Him in that He has guided you; and perchance ye shall be grateful.
[200]: So when ye have accomplished your holy rites, celebrate the praises of Allah, as ye used to celebrate the praises of your fathers,- yea, with far more Heart and soul. There are men who say: "Our Lord! Give us (Thy bounties) in this world!" but they will have no portion in the Hereafter.
[201]: And there are men who say: "Our Lord! Give us good in this world and good in the Hereafter, and defend us from the torment of the Fire!"
[202]: To these will be allotted what they have earned; and Allah is quick in account.
[203]: Celebrate the praises of Allah during the Appointed Days. But if any one hastens to leave in two days, there is no blame on him, and if any one stays on, there is no blame on him, if his aim is to do right. Then fear Allah, and know that ye will surely be gathered unto Him.

Berhasil! Meski hidup tidak mulus di awal, tapi akan ada solusi dari semua permasalahan.
Related Posts Plugin for WordPress, Blogger...