ShellGPT is a command-line productivity tool powered by AI large language models (LLMs), designed to help users complete tasks faster and more efficiently. It provides simplified shell commands, code snippets, and documentation generation without the need for external resources (such as Google search). It supports Linux, macOS, and Windows, and is compatible with mainstream shells such as PowerShell, CMD, Bash, and Zsh.
Key Capabilities
- Generate Shell Commands: Use the
--shellor-soption to generate and execute commands based on the current operating system and shell type. For example, requesting a system update on macOS will return a command suitable for macOS; on Ubuntu, a different suggestion will be returned. - Generate Code: Use the
--codeor-cparameter to request pure code output, and the output can be redirected to a file or input can be passed through a pipe. - Generate Documentation: Can generate documentation content; the specific usage is not described in detail in the materials.
- Analyze Logs: Log content can be passed via standard input, and combined with a prompt to quickly analyze logs, identify errors, and obtain suggested solutions.
- Conversation Feature: Supports chat mode (
--chat) and REPL mode (--repl), and can retain and review conversations. Chat sessions are stored in the configurableCHAT_CACHE_PATH. You can use--list-chatsto list sessions, and--show-chatto display messages from a specific session. - Function Calling: Allows the LLM to execute functions in the system to accomplish various tasks. Default functions can be installed, or custom
~/.config/shell_gpt/functionsto define functions. Note that the LLM may execute destructive commands, and you bear the risk yourself. - Custom Roles: Use
.pyfiles can be created in--create-roleto create custom roles for generating code, shell commands, or meeting specific needs. Role files are stored in~/.config/shell_gpt/roles. You can use--list-rolesto list roles, and--show-roleto display role details. If the role description contains "APPLY MARKDOWN" (case-sensitive), the chat will be displayed in Markdown format unless--no-mdis used to turn it off. - Caching: Use
--cache(default) and--no-cacheto control caching. Identical queries will return results instantly from the local cache. If a different--temperatureor--top-probabilityis specified, a new request will be made. - Shell Integration: Run
sgpt --install-integrationto install; it takes effect after restarting the terminal. A few lines will be added to.bashrcor.zshrc. By default,Ctrl+lis used to invoke ShellGPT, replacing the current input line with the suggested command, which can be edited and executed by pressing Enter.
Usage
- Installation: The materials do not provide specific installation commands, so none are provided for now.
- Configuration: By default, it uses the OpenAI API and the GPT-4 model, and requires an API key, which is stored in
~/.config/shell_gpt/.sgptrc. The OpenAI API is not free; refer to OpenAI pricing for prices. Open-source models can also be run through local backends such as Ollama (free), but ShellGPT is not optimized for local models and may not work as expected. - Input: Accepts standard input and command-line arguments. Input can be passed using pipes and redirection operators.
- Options:
--no-interactiondisables interactive mode and prints the generated command to standard output, making it easy to pass through a pipe (for example, usingpbcopyto copy to the clipboard). - Multiline Prompts: Use triple quotes
""". - REPL mode: an initial prompt can be passed as an argument, via standard input, or both at the same time.
- Runtime configuration file:
~/.config/shell_gpt/.sgptrcparameters can be set, such asDEFAULT_COLOR(possible values: black, red, green, yellow, blue, magenta, cyan, white, bright_black, bright_red, bright_green, bright_yellow, bright_blue, bright_magenta, bright_cyan, bright_white),CODE_THEME(see Pygments styles),MARKDOWN_LIVE_VERTICAL_OVERFLOW(possible values: ellipsis, visible, crop). The default behavior is ellipsis, where only "..." is shown when the Markdown output exceeds the terminal height. visible mode is recommended for REPL sessions, allowing all generated Markdown content to be viewed in real time. - Docker: the container can be run using the
OPENAI_API_KEYenvironment variable and a Docker volume to store the cache. TheOS_NAMEandSHELL_NAMEenvironment variables can be set according to preference. You can also build your own image using the provided Dockerfile.
Use cases
- Quickly generate and look up shell commands, avoiding the need to search online for syntax.
- Generate git commit messages based on a diff.
- Analyze logs and get solutions for errors.
- Generate code snippets and save them to a file.
- Iteratively improve suggestions through conversation.
- Get command suggestions directly in the terminal via a keyboard shortcut.
Limitations
- Uses the OpenAI API by default, which is not free and requires an API key.
- Local models (such as Ollama) are not optimized and may not work as expected.
- Function calls may execute destructive commands, so use with caution.
- The materials do not provide specific installation commands, pricing, platform compatibility details, etc., so these are not provided for now.