combinatrix-ai / ask.sh

ask.sh: AI terminal assistant that can read and write your terminal directly!
30 stars 2 forks source link
assistant bash cli terminal tmux zsh

ask.sh: AI terminal assistant that read from & write to your terminal

Demo

From downloading the Titanic dataset using the curl command to calculate the survival rate for all combinations of sex and room class using the awk command, without leaving the terminal. (Played in 2x. Using gpt-3.5-turbo)

https://github.com/hmirin/ask.sh/assets/1284876/4311db79-c56e-46c9-9cfe-66fce8f800df

You might be interested in other examples

Quick Start

If you're on Bash:

bash -c "$(curl -fsSL https://raw.githubusercontent.com/hmirin/ask.sh/main/install.sh)"

If you're on Zsh:

zsh -c "$(curl -fsSL https://raw.githubusercontent.com/hmirin/ask.sh/main/install.sh)"

Then, follow the instructions shown by the installer. See Setup for manual installation.

Key Features

Query the AI from Your Terminal

No need to bother with a separate browser. Consult the AI about anything directly from your terminal. Here's an example:

❯ ask how to unzip tar gz

The AI responds:

❯ ask how to unzip tar gz
To unzip a tar.gz file, you can use the following command in a terminal:

`tar -xzf file.tar.gz`

where "file.tar.gz" is the name of your compressed file. This command will extract the contents of the file into a directory with the same name as the file. If you want to extract the contents into a different directory, you can specify the path with the -C option:

`tar -xzf file.tar.gz -C /path/to/directory`

Once the extraction is complete, you should have access to the uncompressed files in the directory where you extracted them.

Answers are printed incrementally, ensuring you don't have to wait until the complete response is available!

The AI Understands Your Context!

The AI Terminal Assistant can interpret the context of your actions, providing more meaningful suggestions and explanations. Check this out:

You have typed a command and got error.

❯ rm .git
rm: .git: is a directory

Just ask AI:

❯ ask what does this mean

The AI responds:

❯ ask what does this mean
The message "is a directory" means that you are trying to remove a directory (in this case, the .git directory). In order to remove a directory, you need to use the command "rm -r" instead of just "rm". The "-r" flag tells the "rm" command to remove directories recursively. However, be careful when using this command as it can delete multiple files and directories at once.

Great! Isn't it?

Note: You need to use tmux to use this feature. See Q&A.

Multiturn Conversations with AI in Your Terminal

By understanding the context of your terminal, ask.sh is not just about asking questions and receiving answers; it's about engaging in an insightful dialogue that spans multiple turns. Here's a peek into what that might look like:

❯ git init
Reinitialized existing Git repository in /path/to/ask.sh/.git/

Do you know what exactly happen when you git init again? Let's ask:

❯ ask what does reinitialized mean
"Reinitialized" means that Git has reset the repository's initialization parameters. When you run `git init` in an existing Git repository, Git will re-run the repository's initialization process, but with the existing repository metadata in place. This allows you to reset the repository configuration without losing the existing commit history and other Git metadata.

Hmm, still have question? Ask again:

❯ ask what configuration is reset
When you run init` with the `--reinitialize` or `-o` option, Git will re-run the repository's initialization process, but with the existing repository metadata in place. This allows you to reset the repository configuration without losing the existing commit history and other Git metadata. The specific configuration that is reset depends on what options you passed to `git init`. If you did not pass any options, then Git will reset all initialization parameters to their default values. Is there anything else I can help you with?

Let the AI Write to Your Terminal Directly!

ask command let you type the command AI suggests directly to the shell.

Ask AI to make command like this:

❯ ask allocate 5GB file here

The AI responds with some suggestions of the command:

To allocate a 5GB file here, you can use the `fallocate` command. `fallocate` can be used to allocate space for a file using either the preallocated or the zeroed method.

To allocate space for a 5GB file with the preallocated method, run the following command:

fallocate -l 5G filename


Remember to replace `filename` with the desired name for your file. This will create a file of size 5GB without actually allocating the space until it is actually used.

To allocate space for a 5GB file with the zeroed method, run the following command:

fallocate -l 5G -z filename


This will create a file of size 5GB with all bits set to 0.

If the AI has suggested commands to execute, it will ask if you want to use those commands.

👋 Hey, AI has suggested some commands that can be typed into your terminal.
🔍 Press Enter to view and select the commands, or type any other key to exit:

After you press Enter, an overlay selector (peco) will appear, allowing you to select the most suitable command.

AI suggested commands (Enter to use / Ctrl+C to exit):
fallocate -l 5G filename
fallocate -l 5G -z filename

The selected command is typed into the shell directly. Just hit enter to execute.

❯ fallocate -l 5G filename

You won't struggle text-selection on terminal!

OS / CPU arch / Shell Aware Conversations!

ask command is aware of your shell, OS, and CPU arch. So you can ask shell, OS, and CPU arch specific questions.

❯ ask how to install tmux

The AI responds:

❯ ask how to install tmux
To install tmux on your macOS machine, you can use Homebrew package manager. Here are the steps:

1. Open the terminal.

2. Install Homebrew package manager by running the following command:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"


3. Once Homebrew is installed, install tmux:

brew install tmux


4. Wait for the installation to complete.

That's it! Now you can use tmux on your macOS machine.

Perfect! Isn't it? (Some may not like homebrew though...)

Want to see more?

See examples!

Setup

Prerequisites

Optional, but highly recommended if you want ask command to work more nicely:

Installation

Extras!

License

This project is licensed under the terms of the MIT license.

Disclaimer

Q&A

Why Another Terminal AI Assistant?

Sure, there are plenty of great projects for terminal AI assistants already out there. But, in my experience, none of these tools completely meet the criteria I consider essential:

This is why I created ask.sh.

Similar projects:

How ask.sh send the current output of terminal?

Privacy concerns?

Can I use GPT-4?

Why Rust?

Contributing

Acknowledgements

A special thanks to @xarsh for their effort in debugging, testing, and providing valuable feedback, contributing significantly to the refinement of this project. Our sincere gratitude to @matsurih for their outstanding contribution to our work, marking the project's first-ever PR.