LinuxCommandLibrary

sgpt

AI-powered shell assistant using ChatGPT

TLDR

Ask a question

$ sgpt "[How do I list files?]"
copy
Generate shell command
$ sgpt -s "[list all PDF files]"
copy
Execute shell command
$ sgpt -se "[find large files]"
copy
Generate code
$ sgpt -c "[python function to sort list]"
copy
Chat mode
$ sgpt --chat [session_name] "[message]"
copy
Use specific role
$ sgpt --role [code] "[question]"
copy
Pipe input
$ cat [file.txt] | sgpt "[summarize this]"
copy

SYNOPSIS

sgpt [-s] [-c] [--chat name] [options] prompt

DESCRIPTION

sgpt (Shell GPT) is a command-line interface for interacting with OpenAI's ChatGPT models, optimized for developer and system administration workflows. It operates in several modes: general queries for quick answers, shell mode (-s) for generating executable commands with explanations, and code mode (-c) for producing programming solutions with automatic language detection.
Chat sessions maintain conversation context across multiple invocations, allowing follow-up questions and iterative refinement. Roles customize the AI's behavior for specific tasks, with predefined roles for common scenarios and support for user-defined custom roles.
The tool integrates naturally with Unix pipelines, accepting input via stdin to process file contents, command output, or any streamed data through AI analysis. This makes it useful for tasks like summarizing logs, explaining error messages, or generating documentation from code.

PARAMETERS

-s, --shell

Generate shell command.
-se
Shell and execute.
-c, --code
Generate code.
--chat NAME
Chat session.
--role ROLE
Use role.
--model MODEL
Specify model.
--temperature TEMP
Response randomness.
--no-cache
Disable caching.

CONFIGURATION

OPENAI_API_KEY

Environment variable providing the OpenAI API key for authentication.
~/.config/shell_gpt/.sgptrc
Configuration file for default model, temperature, cache settings, and other preferences.
~/.config/shell_gpt/roles/
Directory containing custom role definitions as text files.

CAVEATS

Requires OpenAI API key. Costs per token. Internet connection needed.

HISTORY

sgpt was created by Farkhod Sadykov for AI-assisted shell usage. It brings ChatGPT capabilities directly to the command line.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community