A lightweight bash function that leverages a local, Dockerized LLM to translate natural language requests into raw terminal commands.
Instead of switching context to a web browser to figure out complex ffmpeg, tar, or find syntax, ask brings the AI directly into your terminal.
- Privacy-First & Local: Runs entirely locally using Ollama inside a Docker container. No data is sent to cloud APIs.
- Safe Execution Design: Unlike other AI CLI tools that blindly execute generated commands,
askpushes the AI's response directly into your terminal's history buffer (history -s). You simply press the[UP]arrow to reveal, review, and safely execute the command. - Strict Prompt Engineering: The system prompt is heavily restricted to prevent the LLM from generating markdown, backticks, or conversational filler, ensuring only the raw command is passed to the history buffer.
- Docker
- A bash-compatible terminal
This script relies on a local Ollama container named ollama. If you do not already have one running, you can spin it up and pull the model with the following commands:
# Start the Ollama container
sudo docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama
# Pull the specific model used by the script
sudo docker exec -it ollama ollama run gemma4(Note: You can easily swap this out for llama3, mistral, or any other model by editing the script).
Clone the repository and append the function to your .bashrc or .bash_aliases file.
git clone https://github.com/rndchris/ask-cli.git
cd ask-cli
cat ask.sh >> ~/.bashrc
source ~/.bashrcSimply type ask followed by what you want to achieve in plain English.
$ ask Extract audio from video.mp4
Asking AI...
✅ Command generated! Press the [UP] arrow to reveal it.Press the [UP] arrow, and the exact command will appear on your prompt line, ready to be executed:
$ ffmpeg -i video.mp4 -vn -c:a libmp3lame audio.mp3The script securely passes your prompt to the local Docker container alongside a strict system message:
You are a CLI expert. Output ONLY the raw terminal command.
Rules:
- NO markdown formatting.
- NO backticks.
- NO explanations.
- NO introductory text.By leveraging history -s "$response", the script manipulates the bash history stack without executing the string, providing a necessary human-in-the-loop security checkpoint.