19 May 2024
Lightning fast AI prompting via the command-line
I recently released kratos.sh, a simple but powerful CLI application that brings AI to your terminal. One of the motivations for building kratos was to increase the speed and efficiency at which I could perform prompts to get information or commands to solve specific issues I was facing in the context of the terminal.
Since then, I have been using kratos every single day, and I had this question in my head: “How can I prompt even faster?”
Currently, for users to perform prompts via kratos, they execute the following command:
kratos ask "<INSERT PROMPT HERE>"
It’s all good, but for die-hard productivity fans, typing all that can be seen as inefficient. So, how can we take this to the next level of efficiency so users can prompt even faster?
UNIX Shell Functions
Shell functions are regular functions that execute in your shell. They are more powerful and flexible compared to UNIX aliases and can accept arguments.
Using shell functions would allow us to type fewer commands to execute our prompts.
Here is what you can do to perform a simple prompt using kratos. These prompts are a good fit if you want a short response, for example, if you want to know the UNIX command to move a file from one directory to another.
kratos ask -m "How can I move a file from one directory to another on a unix based system?"
To speed this up, edit your ~/.zshrc or ~/.bashrc and add the following code:
ai() {
kratos ask -m "$1"
}
To enable this to work in your shell environment, type source ~/.zshrc or source ~/.bashrc depending on your specific shell configuration.
With this, we have essentially added a UNIX shell function ai that accepts an argument $1. This would allow us to perform a prompt with less typing:
ai "How can I move a file from one directory to another on a unix based system?"
If you wanted a more verbose and richer answer, you would execute the following command using kratos
:
kratos ask -m "How can I move a file from one directory to another on a unix based system?"
To speed this up, edit your ~/.zshrc or ~/.bashrc and add the following code:
aiv() {
kratos ask -m "$1" -v
}
This will enable you to perform a prompt in a much faster fashion:
ai "How can I move a file from one directory to another on a unix based system?"
In conclusion, we have learnt how we can leverage UNIX shell functions to significantly enhance the way and speed at which we perform AI prompts using kratos.sh. That’s all for now, happy prompting!