1q: 1 query for the right one-liner.
Sections
Meet 1q: Less Googling, More Doing - My CLI Sidekick!
Hey everyone, gather 'round the virtual terminal! I've been tinkering away on a little CLI tool that I think is pretty darn useful, and I'm excited to share it! It's called 1q (short for 1Query), and it's designed to do one thing really well: turn your everyday English requests into shell commands or code snippets. No more awkwardly phrasing Google searches for that one specific `awk` or `find` command – I built this to be way faster. Let's check it out!
The Endless Command Search? I Built a Solution!
Okay, let's be honest. How many times have you been deep in thought, needing to do something on the command line – like "find all text files modified yesterday in this directory and its subdirectories" – and your brain just... stalls? You *know* there's a command, maybe involving `find` or `grep` or some arcane flags, but remembering the exact syntax? Ugh. So you open a browser, type something vague into Google, sift through Stack Overflow... sound familiar? I found myself doing this constantly, and it felt like such a workflow killer.
That's exactly why I built 1q. It's like having a command-line expert sitting next to you, powered by AI (specifically Google's Gemini). You just type what you want to do in plain English, and 1q gives you the command.
"Wait, you made an AI command generator? Does it actually work?"
Yup, I did! And yeah, it works surprisingly well! I focused on making it simple and direct. Ask a question, get a command. Sometimes it needs a little refinement, but that's built-in too! The goal was to keep me (and hopefully you!) in the terminal, focused on the task, not on searching syntax.
Key Features: Speak Your Mind, Get Your Command!
So what makes 1q tick, and why did I build it this way?
- Natural Language Input: Just type what you need!
1q find files larger than 10MB modified last week
. I wanted it to feel intuitive, like talking to an assistant. - Gemini Powered: It uses Google's Gemini AI (specifically `gemini-1.5-flash`) to understand your request and generate accurate commands or code snippets. I picked Gemini for its strong language understanding capabilities.
- Smart Output (TUI & Inline): Simple query? Get just the command, ready to pipe or use (`inline` mode). More complex query with explanations? Get a nice Textual User Interface (`tui` mode) breaking down the command, explanation, and install steps. I designed the `auto` mode to pick the best view for you.
- Interactive Workflow: Got the command? Great! You can instantly:
- Execute (`x`): Run it right away.
- Modify (`m`): Tweak it before running.
- Copy (`c`): Copy it to your clipboard.
- Refine (`r`): Ask for a change (e.g., "make it recursive"). 1q remembers the context!
- Context-Aware Refinement: Didn't get it perfect first try? Just hit 'r' and tell 1q what to change. It remembers the previous query and response, making refinements easy. This was crucial for me – iteration without starting over.
- Cross-Platform: Built with Python, it runs on Linux, macOS, and Windows. I made sure the prompts to Gemini include OS info for better platform-specific commands!
Under the Hood (Simplified Tech - From Me to You!)
Let's peek under the hood, keeping it simple. I built 1q primarily with Python because it's fantastic for scripting and has great libraries. It's like the Swiss Army knife of programming languages – perfect for a tool like this.
The AI magic comes from the Google Generative AI SDK (google-generativeai
). This is the official library I used to talk to the Gemini API. Think of it as the phone line connecting 1q to the AI brain.
For that cool TUI (Textual User Interface), I used the amazing Textual library. It makes building sophisticated terminal applications way easier than it has any right to be. It's like a framework for making your terminal apps look and feel like modern graphical apps, but with text! Rich (which Textual uses) helps with the nice colors and formatting you see in the prompts and messages. I wanted the interface to be helpful, not just functional.
And for that handy "Copy" command? I brought in Pyperclip, a neat little library that handles clipboard operations across different operating systems. It just makes copying the generated command seamless.
Get 1q Running - It Takes Just a Minute!
Ready to give 1q a whirl? I made the installation super simple using pip.
- Install it via pip: Open your terminal and run:
pip install oneq
(Or even better, usepipx install oneq
for a clean installation!) - Set up your API Key: 1q needs a Google Gemini API key. Get one free from Google AI Studio. You can either:
- Set the
GEMINI_API_KEY
environment variable (recommended). - Or just run
1q
once without the key set, and I built a little setup TUI to guide you through saving it.
- Set the
- Make Your First Query!: Try asking it something!
1q how to check disk space on linux
or1q generate a python function to reverse a string
Boom! You should get a command or snippet back. Interact with it using the prompts (inline or TUI). I hope you find it as helpful as I do!
Ready to Query Your Way Through the Command Line?
So that's 1q! My little contribution to making command-line life a bit easier. I built it to scratch my own itch of constantly breaking focus to search for command syntax. If you spend time in the terminal and sometimes wish you could just *ask* for the command you need, give 1q a try!
Find it on PyPI and GitHub:
PyPI Package (pip install oneq)
GitHub Repository (Check out the code!)
Are you going to use 1q to finally figure out that complicated `git rebase` command? 😉 Let me know what you think! Since I built this, feedback is super valuable. Happy querying!