Gemini CLI examples
Gemini CLI helps you automate common engineering tasks by combining AI reasoning with local system tools. This document provides examples of how to use the CLI for file management, code analysis, and data transformation.
Note: These examples demonstrate potential capabilities. Your actual results can vary based on the model used and your project environment.
Rename your photographs based on content
Section titled “Rename your photographs based on content”You can use Gemini CLI to automate file management tasks that require visual analysis. In this example, Gemini CLI renames images based on their actual subject matter.
Scenario: You have a folder containing the following files:
photos/photo1.pngphotos/photo2.pngphotos/photo3.pngGive Gemini the following prompt:
Rename the photos in my "photos" directory based on their contents.Result: Gemini asks for permission to rename your files.
Select Allow once and your files are renamed:
photos/yellow_flowers.pngphotos/antique_dresser.pngphotos/green_android_robot.pngExplain a repository by reading its code
Section titled “Explain a repository by reading its code”Gemini CLI is effective for rapid codebase exploration. The following example shows how to ask Gemini CLI to fetch, analyze, and summarize a remote project.
Scenario: You want to understand how a popular open-source utility works by inspecting its code, not just its README.
Give Gemini CLI the following prompt:
Clone the 'chalk' repository from https://github.com/chalk/chalk, read its key source files, and explain how it works.Result: Gemini performs a sequence of actions to answer your request.
- First, it asks for permission to run
git cloneto download the repository. - Next, it finds the important source files and asks for permission to read them.
- Finally, after analyzing the code, it provides a summary.
Gemini CLI returns an explanation based on the actual source code:
The `chalk` library is a popular npm package for styling terminal output withcolors. After analyzing the source code, here's how it works:
- **Core functionality:** The main file sets up a chainable API. Each color or modifier (like `bold` or `italic`) is a getter that appends the corresponding ANSI escape code to an internal stack.
- **Chainable API:** When you call `chalk.red.bold('Hello')`, you are accessing getters. The `red` getter adds the red color code, and the `bold` getter adds the bold code.
- **Output generation:** When the chain is treated as a string (e.g., in `console.log`), a final `toString()` method is called. This method joins all the stored ANSI codes, wraps them around the input string ('Hello'), and adds a reset code at the end. This produces the final, styled string that the terminal can render.Combine two spreadsheets into one spreadsheet
Section titled “Combine two spreadsheets into one spreadsheet”Gemini CLI can process and transform data across multiple files. Use this capability to merge reports or reformat data sets without manual copying.
Scenario: You have two .csv files: Revenue - 2023.csv and
Revenue - 2024.csv. Each file contains monthly revenue figures.
Give Gemini CLI the following prompt:
Combine the two .csv files into a single .csv file, with each year a different column.Result: Gemini CLI reads each file and then asks for permission to write a new file. Provide your permission and Gemini CLI provides the combined data:
Month,2023,2024January,0,1000February,0,1200March,0,2400April,900,500May,1000,800June,1000,900July,1200,1000August,1800,400September,2000,2000October,2400,3400November,3400,1800December,2100,9000Run unit tests
Section titled “Run unit tests”Gemini CLI can generate boilerplate code and tests based on your existing implementation. This example demonstrates how to request code coverage for a JavaScript component.
Scenario: You’ve written a simple login page. You wish to write unit tests to ensure that your login page has code coverage.
Give Gemini CLI the following prompt:
Write unit tests for Login.js.Result: Gemini CLI asks for permission to write a new file and creates a test for your login page.
Next steps
Section titled “Next steps”- Follow the File management guide to start working with your codebase.
- Follow the Quickstart to start your first session.
- See the Cheatsheet for a quick reference of available commands.