/hey-comma

Run shell commands using natural language

Primary LanguageTypeScriptMIT LicenseMIT

hey,

Run shell commands using natural language

License: MIT

· Report Bug / Request Feature ·

running command example

Table of Contents

About

Use natural language to run shell commands using GPT-3.

Just say what you want to do and hey, will generate the command for you.

Features

  • use natural language to run shell commands
  • explains files, scripts or any data scripts using GPT-3
  • caches successful commands to speed up future runs

Why?

Shell scrips are powerful, but only if you know how to use them. hey, makes it easier to use shell scripts by using natural language.

Always forget the command to pack a directory into a tarball? Just say it:

hey, create a tarball with all files in the current directory, except javascript files

Install

hey, requires Node.js v14.16 or higher.

npm i -g hey-comma

Note: pnpm does not like the comma, so only the hey alias is available. You can add the alias manually if you want to: alias hey,=hey

Setup

OpenAI API key

hey, uses OpenAI's API to generate the commands. You need to sign up for an OpenAI account and create an API key.

Then, run:

hey, setup

and follow the instructions. This will create a .hey-comma folder in your home directory and store your API key there.

If you're not comfortable with saving your api key as plain text, you can also set your api key as environment variable and configure hey, to read it from there:

export OPENAI_API_KEY=sk-...
hey, config set openai_api_key "env:YOUR_ENV_VAR_NAME"

Usage

hey, currently has two modes: run and explain. Most of the time you don't need to specify the mode specifically, as hey, will automatically detect the mode based on whether you pipe data to it or not.

running command example

hey, run

hey, run is the default mode. It will convert your instruction to a shell command and run it. It will always ask for confirmation before running the command.

hey, create a tarball with all files in the current dir, except js files

You can explicitly specify the mode:

hey, run: what are the largest files in my download directory

(colon is optional)

hey, explain

hey, explain will explain the data you pipe to it.

Note: the piped data will be sent to OpenAI's servers, so you should only pipe data to hey, explain that you are comfortable sharing with OpenAI.

cat mysterious.sh | hey, is this safe to run

You can explicitly specify the mode:

cat script.sh | hey, explain: what does this do

(colon is optional)

Special characters

To pass special characters to the hey,, you can pass them as a quoted string:

hey, "what is the most recent file in ~/Documents?"

Data sent to OpenAI

hey, will send the following data to OpenAI:

  • The command you want to run
  • The data you pipe to hey, explain
  • Your current shell (e.g. bash or zsh)

More examples

running command example

hey, what are the largest files in my download directory
cat salaries.csv | hey, what is the average salary of people with a PhD
cat script.sh | hey, explain

Contributing

Commit messages

This project uses semantic-release for automated release versions. So commits in this project follow the Conventional Commits guidelines. I recommend using commitizen for automated commit messages.