Abstract
- I take advantage of an AI CLI (ai) in Termux to fetch instructions and solutions with out leaving the terminal.
- I put in termai, added a Gemini/OpenAI API key, then run ai to question, generate scripts, or analyze information.
- I pipe scripts or logs into AI to elucidate, debug, or scan for malicious code shortly.
The one factor that slows me down (or at the least used to gradual me down) was having to lookup documentation or instructions whereas working with Termux. So I discovered a strategy to convey an AI assistant (not a coding agent) into Termux. Now I can lookup instructions and seek for stuff on the fly with out leaving the terminal. It is serving to me be taught Termux sooner and saves me the difficulty of switching between apps.
The way it works
I put in a script that lets me use the command-line interface variations of Google Gemini or ChatGPT inside Termux. Accessing it is so simple as sort ai, adopted by a question. For instance, if I need to discover out what command updates the repos and packages in Termux, I may give it a immediate like this.
The CLI software prints simply the instructions I would like. You’ll be able to ask for comparable instructions to put in some other bundle too. You’ll be able to ask this cli software to offer you curl or wget instructions for loading scripts or configuration information. For instance, I may ask it for a script that personalizes the Termux theme.
It additionally is useful if you’d like AI to jot down small scripts for you with out spinning up a coding agent like Gemini CLI (which Termux can even do). Merely sort ai, specify what you need the script to do and what language you need it to be in. Then sort > and the script file title. Whenever you press enter, the brand new script shall be created in the identical listing. For instance, you would ask the AI to jot down a Bash script for producing random passwords.
ai write a small bash script for producing a random password>go.sh
Then you possibly can run it with the Bash command like so.
bash go.sh
The scripts do not should be that easy or trivial both. For instance, you would whip up a Python script that scours Reddit or LinkedIn for job leads and produces the output in a CSV file.
When working with Termux, you may inevitably come throughout scripts that different individuals have written, and also you need to use. This useful software can even provide help to perceive these scripts, debug them, and even scan them for malicious code. All you need to do is cat that script and pipe it by means of to the ai immediate.
cat go.sh | ai what does this script do?
The cat command shows the contents of the file and the pipe | arms off the output of cat to the ai command. You are able to do the identical for error logs or configuration information too.
The best way to arrange the AI assistant inside Termux
You will want three issues to make issues work.
- Termux. Set up the Termux app from F-Droid or GitHub as a result of the Play Retailer model is severely restricted.
- An API key from Google Gemini or OpenAI. The Gemini API secret’s free with some restricted utilization.
- The Git tool for fetching the installer script. Ensure you at all times look at a script earlier than operating it.
As soon as you have put in Termux, open the app and run this command to replace the repositories and packages.
pkg replace && pkg improve -y
Now we are able to set up git.
pkg set up git
We’re prepared to put in the CLI assistant software. Here is the GitHub repo link for the software. Let’s begin by making a brand new folder for it and leaping into it.
mkdir ai
cd ai
Subsequent, we’ll use the git software to clone the repository.
git clone https://github.com/estiaksoyeb/termai
Let’s cd into this repo and run the installer.
cd termai
bash set up.sh
It is best to see a message that “termai” was efficiently put in. The script routinely clears the cloned directories, so that you need not fear about handbook cleanup. Simply press “Y” and hit Enter when prompted.
With the CLI software put in globally, all we’d like now could be the API key to activate it. Let’s strive utilizing the ai command.
ai hi there
On the primary run, it’s going to ask which AI mannequin you need to use. Press 1 for Gemini and a couple of for OpenAI. Then open Google’s AI Studio website and login with a Google account. Search for the “Get API Key” button and press it. Create a brand new challenge right here and duplicate the API key.
Return to Termux and paste the Gemini API Key the place requested. So long as the API secret’s appropriate, and you’ve got free tokens, you possibly can entry Gemini inside Termux. You’ll be able to comply with the question with or with out quotes to get a response.
If you wish to change the API key in a while or if you wish to edit the system immediate, you possibly can edit the configuration file with this command.
ai --config
To take away the software and its configuration information, you possibly can run these three instructions.
rm $PREFIX/bin/ai
rm -rf ~/.applications/termai
rm -rf ~/.native/share/termai
You now have a useful little assistant to tug up instructions and get assist with errors. This software can even provide help to perceive scripts and error logs. It will probably even write scripts.
Source link

