gems.sh is a Zsh script that simplifies interacting with local Large Language Models using Ollama. It provides a rich set of pre-configured prompt templates with advanced features like language detection, JSON schema processing, and flexible output handling.
Inspired by the workflow described in this Hacker News post by eliya_confiant: https://news.ycombinator.com/item?id=39592297.
- Rich Prompt Templates: Load from YAML configuration with templates like TextReviser, CodeReview, ComplexAnalysis
- Multiple Model Support: Use
-mto specify any Ollama model (defaults togemma3n) - Language Detection: Automatic language detection for templates that support it
- JSON Schema Processing: Define expected response structure and extract specific fields
- Template Properties: Configure language detection, output language, and JSON processing per template
- Clipboard Integration: Automatically copies results to clipboard with notifications
- Raw Response Tracking: When using JSON extraction, shows both raw LLM output and extracted result
- Flexible Output Destinations:
Results can be displayed in your choice of viewer:- Terminal
- iTerm2
- Warp
- homo (a custom Markdown viewer; set
RESULT_VIEWER_APP="homo")
-
Ollama (Required)
brew install ollama # Start the service ollama serve -
macOS Tools (Required - built-in)
osascript(AppleScript support)pbcopy(clipboard functionality)
-
YAML Processing (Recommended)
brew install yq
- Required for loading templates from
gems.yml
- Required for loading templates from
-
JSON Processing (Recommended)
brew install jq
- Required for JSON schema features
-
Markdown Rendering with homo (Recommended)
-
Markdown Rendering (Optional)
brew install glow
- For Terminal/iTerm2 markdown display
-
Path Resolution (Optional)
brew install coreutils
- Provides
realpathfor better path handling
- Provides
Download the default models:
ollama pull gemma3n # Default model
ollama pull gemma3n:e2b # Language detection modelCreate a gems.yml file in the same directory as gems.sh:
prompt_templates:
TextReviser:
template: |
Revise the following text for clarity, grammar, and readability.
Text: {{input}}
properties:
detect_language: true
json_schema:
revised_text: string
additional_info: string
json_field: revised_text
CodeReview:
template: |
Review this code for best practices and potential improvements.
Code: {{input}}
properties:
json_schema:
issues:
- type: string
severity: string
description: string
summary: string
json_field: summaryEdit the configuration section in gems.sh:
# LLM settings
DEFAULT_MODEL="gemma3n"
LANGUAGE_DETECTION_MODEL="gemma3n:e2b"
# Output settings
RESULT_VIEWER_APP="homo" # Options: homo, Warp, Terminal, iTerm2# Use default template (Passthrough)
./gems.sh "Explain quantum computing"
# Specify a template
./gems.sh -t TextReviser "Me and him went to store"
# Use specific model
./gems.sh -m gemma3:27b-it-qat -t CodeReview "function buggyCode() { return x + y; }"
# Verbose mode for debugging
./gems.sh -v -t ComplexAnalysis "Sample text to analyze"Language Detection:
# Automatically detects input language and preserves it
./gems.sh -t TextReviser "Bonjour, comment allez-vous?"JSON Schema Processing:
# Returns structured data and extracts specific fields
./gems.sh -t ComplexAnalysis "This is a complex document to analyze"
# Returns only the 'summary' field due to json_field configurationTemplate Management:
# List available templates and models
./gems.sh -h
# Check dependencies
./gems.sh -v -t Passthrough "test" | head -20detect_language: true- Auto-detect input languageoutput_language: "English"- Force specific output languagejson_schema: {...}- Define expected JSON response structurejson_field: "fieldname"- Extract specific field from JSON response
# Language detection with JSON output
TranslationAnalysis:
template: "Analyze and translate: {{input}}"
properties:
detect_language: true
json_schema:
original_language: string
translation: string
confidence: number
json_field: translation
# Complex analysis with structured output
DocumentAnalysis:
template: "Analyze this document: {{input}}"
properties:
json_schema:
analysis:
topics: [string]
sentiment: string
summary: string
json_field: summary
- Open Shortcuts App
- Create New Shortcut named "Ask AI"
- Add Actions:
- "Get Text from Input" (set to receive text from Quick Actions)
- "Run Shell Script" with:
/path/to/gems.sh "$@"
- Configure Quick Actions to accept text input
- Optional: Add keyboard shortcut in shortcut settings
Usage: Select text → Right-click → "Ask AI" or use keyboard shortcut
Click to expand Automator setup
- Open Automator → Create Quick Action
- Add "Run Shell Script" action
- Paste gems.sh contents or call script with full path
- Save as service
- Assign keyboard shortcut in System Settings → Keyboard → Shortcuts
The included gems.yml provides these templates:
- Summarize - Create concise summaries
- TextReviser - Grammar and clarity improvements
- EmailProfessional - Convert to professional email format
- BulletPoints - Convert text to organized bullet points
- ComplexAnalysis - Comprehensive text analysis with sentiment and topics
- ProsAndCons - Balanced analysis of topics
- CodeReview - Best practices and security review
- CodeExplain - Simple explanations of code
- CodeOptimize - Performance and readability improvements
- Brainstorm - Generate creative ideas and solutions
./gems.sh -v -t Passthrough "test" 2>&1 | grep -E "(ERROR|WARNING|✓)""No templates found":
- Ensure
gems.ymlexists in script directory - Install
yq:brew install yq - Check YAML syntax with:
yq eval . gems.yml
"Model not found":
- List available models:
ollama list - Pull required model:
ollama pull model-name
"JSON extraction failed":
- Install
jq:brew install jq - Check template's
json_schemaconfiguration - Use
-vflag to see raw LLM response