Shell-GPT: Your Interactive AI Assistant in the Linux Shell

Author: Cal

Table of Contents

Shell-GPT: Your Interactive AI Assistant in the Linux Shell

Co-pilot-like control of your desktop using a cli chatbot

Shell-GPT is a practical tool for enhancing user control through a command-line interface using LLMs to simplify everyday tasks. The accompanying GIF demonstrates a user typing sgpt "toggle gnome 46 darkmode on" into the terminal, highlighting the tool’s ability to interpret plain English commands and interact with the system. It can act as a chatbot with Windows Co-Pilot-like abilities or as a natural language instruction pipeline to simplify the user’s life and enable interesting functionality that would otherwise be very difficult to implement.

Shell-GPT, where your shell gains superpowers. Below, I used Shell-GPT’s REPL mode, function calling, and a custom role description to assist with managing my email communications in a chatbot-like workflow.

To handle the reply, I asked Echo to draft a response, giving it a short answer of how I wanted to proceed. Echo generated a professional email draft, which I reviewed and approved. Finally, Echo saved the draft to my clipboard, ready for sending.

This interaction highlights the efficiency and convenience Shell-GPT brings to everyday tasks, making it a valuable tool for anyone working in a Linux shell environment. Check out the GIF above to see Shell-GPT in action!

This example, while silly, showcases the practical applications of Shell-GPT in real-life scenarios. With long email chains spanning days or weeks, Echo is even more useful as it catches little points and details that are easy to forget or overlook.

Beyond email management, I also use Shell-GPT to do random tasks like converting screencast videos into GIFs for this blog post. The first time I attempted this, I didn’t have ffmpeg installed… Echo noticed the command failure, installed ffmpeg, and retried without further interaction.

The REPL functionality is particularly useful for interactive workflows, allowing for detailed, step-by-step task execution. However, Shell-GPT is equally adept at handling one-off CLI commands, piping data in and out efficiently. The CLI has flags to output structured code or text, which is incredibly handy for creating files. Here are a few examples I use often:

cat index.md | sgpt "Can you find errors in my file? List potential improvements in bullet points" # Explains how I can improve a blog post
alias bcom='wl-paste | sgpt --role bcom' # Grabs the email in my clipboard and professionalizes it with the bcom role
sgpt "generate a new ssh key for use with GitHub"
sgpt "use notmuch to check email from and to Chad. When will he be out of the office?"

You can configure custom roles by running sgpt --create-role role-name. Roles are essentially prompting instructions that prefix your input, allowing you to tell the system how to respond in a reusable way. I’m particularly proud of my bcom role, which produces polished business emails that don’t sound like they were written by ChatGPT. Here is the prompt:

Write a refined and professional email based on the provided draft. Avoid introductory phrases such as "I hope this email finds you well." Maintain a tone and style similar to contemporary business literature. Use common American phrasing and vocabulary, and steer clear of non-American English expressions or styles.

For more in-depth email responses, I use a similar prompt:

{"name": "email", "role": "You are email\nWrite a refined and professional email based on the provided email chain and response points. Avoid introductory phrases such as \"I hope this email finds you well.\" Maintain a tone and style similar to contemporary business literature. Use common American phrasing and vocabulary, and steer clear of non-American English expressions or styles. Process: 1. Participants Summary: List the participants along with their roles, responsibilities, or titles. Summarize their input and likely concerns from the conversation, as stated or assumed from context. 2. Email Chain Summary: Provide a short, clear summary of the email chain to this point, specifically listing the current open status items. 3. Planned Response: Using the provided draft or list of response points, plan the response. State clearly the audience of the message, the tone, and list the points to be made. 4. Generate the Message: Write the email based on the planned response. 5. Self-Assessment: Grade the draft based on the following criteria: Tone Matching the Guidelines: A-F; Message Accomplishes Its Goals: A-F; Clarity of Message: A-F"}

This prompt is designed to write a professional email based on a complete email chain and some response points. Here’s a step-by-step breakdown of how it works:

  1. Participants Summary: The AI will list everyone involved in the email chain, along with their roles or titles. It will summarize what each person has said and what their concerns might be.
  2. Email Chain Summary: The AI will provide a brief summary of the entire email conversation so far, highlighting any open issues that need to be addressed.
  3. Planned Response: Using the provided draft or response points, the AI will plan the response. It will identify the audience, decide on the tone, and list the key points to be made.
  4. Generate the Message: The AI will then write the email based on the planned response.
  5. Self-Assessment: Finally, the AI will grade the draft based on three criteria:
    • Tone Matching the Guidelines: Does the email match the required tone?
    • Message Accomplishes Its Goals: Does the email achieve what it is supposed to?
    • Clarity of Message: Is the email clear and easy to understand?

This process ensures that the AI creates a refined and professional email that fits the context and addresses all necessary points.

It does a fantastic job of making me look like I spent a lot of effort on a reply when I don’t have the time to write out a detailed response. Usage would be something like this:

[~] 🌒 notmuch search --output=files 'subject:"Request for Lawn Gnome Parade Service"' | xargs -d '\n' cat | s --role email "Answer: I can't do less than 200. What if I throw in a gallon of moonshine and a gallon of Momma's famous sweet tea. Let him know it will cost too much to travel that far for less."

This example is a bit contrived, sticking with our earlier silly scenario, but it demonstrates how the role instruction can match a specific tone effectively.

I’ve barely scratched the surface of how Shell-GPT works, but I’ve integrated it deeply into my workflow. Take a look at this Github link and consider supporting the project.

QR code to a Mastodon post

Comments

You can comment on this blog post by publicly replying to this post using a Mastodon or other ActivityPub/Fediverse account. Known non-private replies are displayed below.

Load Comments


Go to Top