As part of my preparation for moving to Malaysia for higher studies, I needed to learn the Malay language. Being a frequent terminal user on Linux, I decided to integrate language learning into my daily workflow. I wrote this script and added it to my .zshrc
file so that each new terminal session presents three new Malay words
- BASH
- jq - For JSON parsing.
- curl - To handle API requests.
- Linux (Fedora)
- Visual Studio Code (VS Code) for development.
- Shellcheck - Used to ensure proper syntax and detect potential issues in the script.
- learn-malay.sh - Main script, Where the logic happens.
- gemini.conf - Holds the API key and configuration data for the gemini API.
- word-list.csv - Pre-defined list of words Stored to fetch translations.
- data.state - Tracks the user's progress, including the last accessed date and day.
- response.json - Stores the last API response to enable offline access and to minimize API calls.
/usr/local/
|--- etc/
| |--- let-s-learn-malay/
| |--- word-list.csv
| |--- gemini.conf
|
|--- bin/
|--- learn-malay (learn-malay.sh)
git clone <repo>
cd Lets-Learn-Malay
Add the gemini API key into
gemini.conf
file
sudo mkdir let-s-learn-malay /usr/local/etc
sudo chown $USER:$USER -R /usr/local/etc/let-s-learn-malay
mv let-s-learn-malay/gemini.conf let-s-learn-malay/word-list.csv /usr/local/etc/let-s-learn-malay
mv learn-malay.sh learn-malay
mv learn-malay /usr/local/bin
Now use the script as a standard command by typing
learn-malay
additionally add the command to
.zshrc
or.bashrc
file
-
The script displays three Malay words per day.
-
For each word it provides:
* Malay word bas
* Pronunciation guide for English speakers 'bass'
* English Definition bus
* Example Malay sentences with English translations for better context. Bas itu penuh sesak. ─ The bus is crowded.
- The script adapts its output to the terminal window size. If the terminal has more space, it organizes data into single-row displays; otherwise, it dynamically splits the content into two or three rows, ensuring an optimal user experience regardless of terminal size.
- Instead of fetching data each time the script will save the data to use again.
- If for any reasons script couldn't fetch new data from API script will output previously saved data to avoid interruptions to avoid interruptions to the learning process
- If the
word-list.csv
does not exist the model will generate three words according to the learning state.
- The learning state, including the last accessed day and the words shown, is tracked in a state file. This ensures that each user session picks up from where it left off, providing a seamless learning journey.