Skip to content

Instantly share code, notes, and snippets.

@susliko
Created April 26, 2026 17:33
Show Gist options
  • Select an option

  • Save susliko/6111b411e3a46e15e99ed0cf5e657d14 to your computer and use it in GitHub Desktop.

Select an option

Save susliko/6111b411e3a46e15e99ed0cf5e657d14 to your computer and use it in GitHub Desktop.
howdoi - Ask pi for shell commands

howdoi

Ask pi for shell commands without leaving your terminal.

Requirements

  • pi - AI coding agent
  • jq (optional, for environment caching)

Installation

curl -sL https://gist.github.com/YOUR_GIST_ID/raw/howdoi -o ~/bin/howdoi
chmod +x ~/bin/howdoi

Usage

howdoi "install gh on manjaro"
howdoi "count scala lines"
howdoi "restart docker on ubuntu"

How it works

  1. Caches your environment (distro, package managers) on first run
  2. Calls pi with your question + environment context
  3. Returns a single command with explanation and alternatives

Output format

sudo pacman -S github-cli

Explanation:
- sudo - run with root privileges
- pacman -S - install from repositories
- github-cli - the package name

Alternatives:
- yay -S github-cli - from AUR
- git clone ... - build from source

Notes

  • Wrap your query in quotes if it contains special characters: howdoi "install on manjaro?"
  • First run is slightly slower (model cold start)
  • Subsequent runs are faster (cached environment)
#!/bin/bash
# howdoi - Ask pi for shell commands
# Usage: howdoi "how do i count scala lines"
# howdoi "install gh on manjaro"
#
# Requires: pi (https://github.com/badlogic/pi)
# Optional: jq for better env caching
CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/howdoi"
ENV_CACHE="$CACHE_DIR/env.json"
# Detect and cache env info (runs once, reused)
if [ ! -f "$ENV_CACHE" ]; then
mkdir -p "$CACHE_DIR"
DISTRO=$(cat /etc/os-release 2>/dev/null | grep PRETTY_NAME | cut -d= -f2 | tr -d '"')
PKGMGR=""
for pm in pacman apt dnf brew yum apk; do
if which $pm &>/dev/null; then
PKGMGR="${PKGMGR}${PKGMGR:+,}$pm"
fi
done
echo "{\"distro\":\"$DISTRO\",\"pkgmgr\":\"$PKGMGR\"}" > "$ENV_CACHE"
fi
# Read cached info
ENV_INFO=$(cat "$ENV_CACHE" | jq -r ' "Environment: \(.distro). Package managers: \(.pkgmgr)."')
pi -p \
--system-prompt "Shell expert answering: $ENV_INFO. Format: command on line 1 (NO backticks, NO code blocks), blank line, 'Explanation:' with dash list, 'Alternatives:' with alternatives." \
--no-builtin-tools \
"howdoi: $*"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment