# ShellGPT | Productivity Tool To Accomplish Your Tasks Faster And More Efficiently

**URL:** <https://onehack.st/t/shellgpt-productivity-tool-to-accomplish-your-tasks-faster-and-more-efficiently/295463>\
**Category:** Tools & Scripts\
**Tags:** programming, tips-tricks, ai\
**Created:** [November 10, 2024, 10:08am UTC](https://onehack.st/t/shellgpt-productivity-tool-to-accomplish-your-tasks-faster-and-more-efficiently/295463 "2024-11-10T10:08:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![WhiteHat](https://onehack.st/user_avatar/onehack.st/whitehat/32/162514_2.png) [@WhiteHat](https://onehack.st/u/WhiteHat)\
**Post date:** [November 10, 2024, 10:08am UTC](https://onehack.st/t/shellgpt-productivity-tool-to-accomplish-your-tasks-faster-and-more-efficiently/295463/1 "2024-11-10T10:08:05Z")

</div>

![sddefault](https://onehack.st/uploads/default/original/3X/5/d/5d14f3de272321307407d1842b043704e7961017.jpeg)

# ShellGPT

A command-line productivity tool powered by AI large language models (LLM). This command-line tool offers streamlined generation of **shell commands, code snippets, documentation** , eliminating the need for external resources (like Google search). Supports Linux, macOS, Windows and compatible with all major Shells like PowerShell, CMD, Bash, Zsh, etc.

## Installation

`pip install shell-gpt`

By default, ShellGPT uses OpenAI’s API and GPT-4 model. You’ll need an API key, you can generate one [here](https://beta.openai.com/account/api-keys). You will be prompted for your key which will then be stored in `~/.config/shell_gpt/.sgptrc`. OpenAI API is not free of charge, please refer to the [OpenAI pricing](https://openai.com/pricing) for more information.

**Tip**

Alternatively, you can use locally hosted open source models which are available for free. To use local models, you will need to run your own LLM backend server such as [Ollama](https://github.com/ollama/ollama). To set up ShellGPT with Ollama, please follow this comprehensive [guide](https://github.com/TheR1D/shell_gpt/wiki/Ollama).

**❗Note that ShellGPT is not optimized for local models and may not work as expected.**

## Usage

**ShellGPT** is designed to quickly analyse and retrieve information. It’s useful for straightforward requests ranging from technical configurations to general knowledge.

sgpt “What is the fibonacci sequence” # → The Fibonacci sequence is a series of numbers where each number …

ShellGPT accepts prompt from both stdin and command line argument. Whether you prefer piping input through the terminal or specifying it directly as arguments, `sgpt` got you covered. For example, you can easily generate a git commit message based on a diff:

git diff | sgpt “Generate git commit message, for my changes” # → Added main feature details into README.md

You can analyze logs from various sources by passing them using stdin, along with a prompt. For instance, we can use it to quickly analyze logs, identify errors and get suggestions for possible solutions:

docker logs -n 20 my\_app | sgpt “check logs, find errors, provide possible solutions”

```auto
Error Detected: Connection timeout at line 7.
Possible Solution: Check network connectivity and firewall settings.
Error Detected: Memory allocation failed at line 12.
Possible Solution: Consider increasing memory allocation or optimizing application memory usage.

```

You can also use all kind of redirection operators to pass input:

sgpt “summarise” \< document.txt # → The document discusses the impact… sgpt \<\< EOF What is the best way to lear Golang? Provide simple hello world example. EOF # → The best way to learn Golang… sgpt \<\<\< “What is the best way to learn shell redirects?” # → The best way to learn shell redirects is through…

### Shell commands

Have you ever found yourself forgetting common shell commands, such as `find`, and needing to look up the syntax online? With `--shell` or shortcut `-s` option, you can quickly generate and execute the commands you need right in the terminal.

sgpt --shell “find all json files in current folder” # → find . -type f -name “\*.json” # → [E]xecute, [D]escribe, [A]bort: e

Shell GPT is aware of OS and `$SHELL` you are using, it will provide shell command for specific system you have. For instance, if you ask `sgpt` to update your system, it will return a command based on your OS. Here’s an example using macOS:

sgpt -s “update my system” # → sudo softwareupdate -i -a # → [E]xecute, [D]escribe, [A]bort: e

The same prompt, when used on Ubuntu, will generate a different suggestion:

sgpt -s “update my system” # → sudo apt update && sudo apt upgrade -y # → [E]xecute, [D]escribe, [A]bort: e

Let’s try it with Docker:

sgpt -s “start nginx container, mount ./index.html” # → docker run -d -p 80:80 -v $(pwd)/index.html:/usr/share/nginx/html/index.html nginx # → [E]xecute, [D]escribe, [A]bort: e

We can still use pipes to pass input to `sgpt` and generate shell commands:

sgpt -s “POST localhost with” \< data.json # → curl -X POST -H “Content-Type: application/json” -d ‘{“a”: 1, “b”: 2}’ [http://localhost](http://localhost) # → [E]xecute, [D]escribe, [A]bort: e

Applying additional shell magic in our prompt, in this example passing file names to `ffmpeg`:

ls # → 1.mp4 2.mp4 3.mp4 sgpt -s “ffmpeg combine $(ls -m) into one video file without audio.” # → ffmpeg -i 1.mp4 -i 2.mp4 -i 3.mp4 -filter\_complex “[0:v] [1:v] [2:v] concat=n=3:v=1 [v]” -map “[v]” out.mp4 # → [E]xecute, [D]escribe, [A]bort: e

If you would like to pass generated shell command using pipe, you can use `--no-interaction` option. This will disable interactive mode and will print generated command to stdout. In this example we are using `pbcopy` to copy generated command to clipboard:

sgpt -s “find all json files in current folder” --no-interaction | pbcopy

### Shell integration

This is a **very handy feature** , which allows you to use `sgpt` shell completions directly in your terminal, without the need to type `sgpt` with prompt and arguments. Shell integration enables the use of ShellGPT with hotkeys in your terminal, supported by both Bash and ZSH shells. This feature puts `sgpt` completions directly into terminal buffer (input line), allowing for immediate editing of suggested commands.

Shell\_GPT\_Integration.mp4

To install shell integration, run `sgpt --install-integration` and restart your terminal to apply changes. This will add few lines to your `.bashrc` or `.zshrc` file. After that, you can use `Ctrl+l` (by default) to invoke ShellGPT. When you press `Ctrl+l` it will replace you current input line (buffer) with suggested command. You can then edit it and just press `Enter` to execute.

To start a conversation, use the `--chat` option followed by a unique session name and a prompt.

## GitHub:

> **[GitHub - TheR1D/shell\_gpt: A command-line productivity tool powered by AI...](https://github.com/TheR1D/shell_gpt)**
>
> A command-line productivity tool powered by AI large language models like GPT-4, will help you accomplish your tasks faster and more efficiently.

---

<div class="post-metadata">

**Author:** ![marca](https://onehack.st/user_avatar/onehack.st/marca/32/152019_2.png) [@marca](https://onehack.st/u/marca)\
**Post date:** [February 3, 2025, 12:25pm UTC](https://onehack.st/t/shellgpt-productivity-tool-to-accomplish-your-tasks-faster-and-more-efficiently/295463/2 "2025-02-03T12:25:22Z")

</div>

After weeks mof trying it again and again I ended up with not being able to launch the AWS Server where I wanted Ollama to be deployed on. Even if I pay for it, it want increase my vCPU limit.  
Where do you ShellGPT run on?
