Exploring the Gemini CLI
I have just started working with the Gemini CLI, and here are a few things I discovered that helped me be more productive. If you haven't tried out the tool, consider doing that! The free tier is very generous.
For reference, you can find Gemini CLI on GitHub. Here's how to install it:
npm install -g @google/gemini-cli
gemini
Here are six things I discovered this week:
1. Provide context first
Always start your session by giving Gemini context about your project. If your very first prompt is something like the following, you’ll be off to a great start.
Example prompt: "Read the source code and identify all files relevant to ..." (add the task you're about to do)
2. Start with a plan
Instead of jumping straight into coding, begin by outlining your goal and collaborating on a plan. This helps you be more specific in your instructions, which leads to better results.
Example prompt: "I want to implement feature X. Let's discuss it together and create an implementation plan before you start coding."
3. Create strong feedback loops
Context is everything. The more relevant information you provide, the better it can assist you. Don't copy and paste errors, make sure Gemini sees them before you do!
You can build these loops in a few ways. First, insist on including unit tests to verify
the code's functionality, then run them within the CLI or direct Gemini to execute them
after making changes. Second, request thorough logging to trace execution flows and
pinpoint issues during runs. Finally, execute scripts directly in the CLI using the
! prefix (for example, !python script.py), allowing you to
feed any runtime errors straight back into your next prompt with a quick instruction to
fix them.
4. Use the escape key
Don't be afraid to reject a suggestion if it doesn't seem right. You are in control of the process.
If Gemini proposes an action (like writing a file or generating code) that is heading
down the wrong path, you can interrupt it immediately by hitting the
ESC key. Once canceled, just continue the conversation to
guide it back on track. For instance, you could say,
“That doesn’t seem right, can you do a web search first?” to direct its next
steps.
5. Your on-demand scripting expert
Use Gemini to generate shell commands you can't quite remember. This saves you from
having to search for the right syntax and flags. If it doesn't seem to know the command,
just tell it to figure it out through using the --help flag.
Example Prompt:
"Write a bash script to convert all .HEIC files in the current directory
to .jpg and resize them to a maximum width of 1200 pixels."
6. Finish the task with Git: commit and push
When you've finished implementing a feature, you can hand off the entire Git workflow. Gemini will:
- Summarize the work completed.
- Check the
git status. - Stage all the new and modified files.
- Write a detailed, conventional commit message based on the context of the tasks it just performed.
- Confirm with you before committing and pushing.
Example Prompt: "Okay, it's done. Please commit and push the changes."