-
-
Save marcdix/5bf4ac3840cbb2c83d734dd3bb3dd783 to your computer and use it in GitHub Desktop.
say2shell [Linux only + needs claude binary]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| VERSION="1.0.0" | |
| if [[ $# -gt 0 ]] && [[ "$1" == "--version" || "$1" == "-v" ]]; then | |
| echo "$VERSION" | |
| exit 0 | |
| fi | |
| if [[ $# -gt 0 ]]; then | |
| input="$*" | |
| elif [[ -t 0 ]]; then | |
| echo "Usage: s2s <natural language instruction>" >&2 | |
| exit 2 | |
| else | |
| input="$(cat)" | |
| fi | |
| # --system-prompt flag causes hangs, so embed instructions in user prompt instead | |
| prompt="Convert this to a single POSIX shell command for Ubuntu. Output ONLY the raw command - no markdown, no backticks, no explanations, no extra text. Prefer common tools (grep, find, awk, sed, tar, zip, ffmpeg, imagemagick, pdfunite). Use safe default filenames if needed (output.pdf, result.txt). Avoid destructive operations unless explicitly requested. | |
| User request: $input" | |
| # Haiku for speed | |
| cmd="$(claude -p --model claude-haiku-4-5-20251001 --output-format text "$prompt" 2>/dev/null)" | |
| cmd="$(printf '%s' "$cmd" | sed -e 's/^```.*$//' -e 's/^The command is://' -e '/^[[:space:]]*$/d' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | head -n1)" | |
| if [[ -z "$cmd" ]]; then | |
| echo "S2S: Failed to generate command" >&2 | |
| exit 1 | |
| fi | |
| printf '%s\n' "$cmd" | |
| if [[ -n "${WAYLAND_DISPLAY:-}" ]] || [[ "${XDG_SESSION_TYPE:-}" == "wayland" ]]; then | |
| printf '%s' "$cmd" | wl-copy 2>/dev/null || true | |
| elif [[ -n "${DISPLAY:-}" ]] || [[ "${XDG_SESSION_TYPE:-}" == "x11" ]]; then | |
| printf '%s' "$cmd" | xclip -selection clipboard 2>/dev/null || \ | |
| printf '%s' "$cmd" | xsel --clipboard 2>/dev/null || true | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment