shell-ask

shell-ask

Ask LLM directly from your terminal

Stars: 330

Visit
 screenshot

Shell Ask is a command-line tool that enables users to interact with various language models through a simple interface. It supports multiple LLMs such as OpenAI, Anthropic, Ollama, and Google Gemini. Users can ask questions, provide context through command output, select models interactively, and define reusable AI commands. The tool allows piping the output of other programs for enhanced functionality. With AI command presets and configuration options, Shell Ask provides a versatile and efficient way to leverage language models for various tasks.

README:

shell-ask

preview


Shell Ask is sponsored by ChatKit, a free chat app for ChatGPT and many other models.

Install

This requires Node.js to be installed.

npm i -g shell-ask

Supported LLMs

Configuration

Minimal config to use OpenAI, create a ~/.config/shell-ask/config.json with the following content:

{
  "openai_api_key": "sk-your-key-xxx"
}

Check out config documentation for more.

Usage

Ask a question:

# Ask a question
ask "get git logs first line only"

# Make sure it outputs a command only with -c or --command flag
ask "get git logs first line only" -c

Using command output as context:

cat package.json | ask "please fix exports"

Interactively select a model:

# show all models
ask quest -m
# show all gpt models
ask quest -m gpt
# show all claude models
ask quest -m claude
# show all ollama models
ask quest -m ollama
# show all groq models
ask quest -m groq

Select a model by id:

ask "question" -m gpt-4o
ask "question" -m claude-3-opus

Prompt without quotes:

# Same prompt
ask "how to delete a docker image"
ask how to delete a docker image

# Escape using backslash if you need quotes inside the prompt
ask who\'s john titor

Piping

You can pipe the output of other programs to ask, for example you can use cat to add file contents to the LLM context:

cat main.ts | ask "explain the code"

If you want to add multiple files, especially when you also want to include filenames in the context, you can use --files flag to add files into model context:

ask --files "src/*.ts " "write a concise outline for this project"

Ask Follow-up Questions

Using -r or --reply flag to ask follow-up questions to the previous answer:

ask "how to delete a docker image"

ask -r "delete last 30 days"

Result Type

Command

Using -c or --command flag to enforce the output to be a command only:

ask "turn foo.mp4 to 720p using ffmpeg" -c

Using -b or --breakdown flag to return a command and the breakdown of the command:

ask "turn foo.mp4 to 720p using ffmpeg" -b

Custom Type

Define the type of the result using -t or --type flag:

cat package.json | ask "extract dependency names" -t "string[]"

cat README.md | ask "extract headings" -t "{depth:number,title:string}[]"

Web Search

Enable web search by using -s or --search flag:

ask -s "how to delete a docker image"

Web search is powered by https://s.jina.ai

Fetching Web Pages

For a single page, you can just use curl:

curl -s https://example.com | ask "summarize it"

For multiple pages, you can use -u or --url flag:

ask -u https://example.com/about -u https://example.com/introduction "summarize it"

You may only need the markdown output of the web page, you can use https://r.jina.ai to retrive markdown content instead:

ask -u https://r.jina.ai/example.com "summarize it"

Disable Streaming Output

Using --no-stream flag to disable streaming output:

ask "how to delete a docker image" --no-stream

When --no-stream is enabled the output markdown will have proper syntax highlighting, when streaming is enabled the output will be plain text because the terminal have trouble clearing the screen when the output is too long

Reusable AI Commands

Shell Ask allows you to define reusable AI commands in the config file, for example the builtin ask cm command:

{
  "commands": [
    {
      "command": "cm",
      "description": "Generate git commit message based on git diff output",
      "prompt": "Generate git commit message following Conventional Commits specification based on the git diff output in stdin\nYou must return a commit message only, without any other text or quotes."
    }
  ]
}

Built-in AI Commands

  • ask cm: Generate git commit message from stdin
    • example: git diff | ask cm

License

MIT.

For Tasks:

Click tags to check more tools for each tasks

For Jobs:

Alternative AI tools for shell-ask

Similar Open Source Tools

For similar tasks

For similar jobs