惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
J
Java Code Geeks
博客园 - 聂微东
量子位
C
Check Point Blog
T
The Blog of Author Tim Ferriss
T
Tailwind CSS Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
B
Blog
罗磊的独立博客
腾讯CDC
GbyAI
GbyAI
博客园 - 【当耐特】
A
About on SuperTechFans
M
MIT News - Artificial intelligence
U
Unit 42
D
Docker
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Y
Y Combinator Blog
大猫的无限游戏
大猫的无限游戏
小众软件
小众软件
S
SegmentFault 最新的问题
有赞技术团队
有赞技术团队

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
A 7-line shell function for one-liner AI answers
Harshit Luth · 2026-05-20 · via DEV Community

Originally published at harshit.cloud on 2026-05-20.


I kept opening a chat tab just to ask "what's the kubectl command for decoding a secret" or "convert 42 GiB to bytes". The context switch was costing more than the answer was worth.

Wrapped my AI CLI (pi here, but the same shape works for claude -p, llm, gh copilot, etc.) into a p function that always returns a single line.

the function

# p: one-shot AI query — `p whats 2 + 2`, `p kubectl secret decode grafana`
p() {
  if [ $# -eq 0 ]; then
    echo "usage: p <question or task>" >&2
    return 1
  fi
  pi -p --no-session --append-system-prompt 'Answer in ONE line. No preamble, no explanation, no markdown, no code fences. For shell/kubectl/git/etc requests output only the command. For factual or math questions output only the answer.' "$*"
}

Enter fullscreen mode Exit fullscreen mode

Three flags carry all the weight:

  • -p — non-interactive, print and exit
  • --no-session — don't persist to session history, every call is ephemeral
  • --append-system-prompt — force one-line, no markdown, no preamble

what it feels like

$ p whats 2 + 2
4

$ p kubectl secret decode grafana
kubectl get secret grafana -o go-template='{{range $k,$v := .data}}{{$k}}: {{$v | base64decode}}{{"\n"}}{{end}}'

$ p convert 42 GiB to bytes
45097156608

$ p git undo last commit but keep changes
git reset --soft HEAD~1

$ p regex for matching an email
[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}

Enter fullscreen mode Exit fullscreen mode

No chat window, no scrolling, no "Certainly! Here's the command you asked for:" preamble. Just the answer.

why "$*" and not "$@"

"$*" joins all positional args into one string with spaces between them. "$@" would pass them as separate args, which most AI CLIs would then concatenate anyway — but some treat the first positional as the prompt and the rest as files. Joining explicitly avoids that ambiguity.

If your CLI of choice supports -- to end option parsing, prefer:

your-ai-cli -p ... -- "$*"

Enter fullscreen mode Exit fullscreen mode

pi doesn't, hence the bare "$*".

the system-prompt nudge actually matters

Without --append-system-prompt, even with -p, the default coding-assistant prompt loves to wrap shell commands in code fences and add a one-sentence intro. That breaks copy-paste and clutters the terminal.

The phrasing that worked best in testing:

Answer in ONE line. No preamble, no explanation, no markdown, no code fences. For shell/kubectl/git/etc requests output only the command. For factual or math questions output only the answer.

The "No markdown, no code fences" line is doing most of the work. Without it you get backtick-wrapped output that won't pipe.

variations worth knowing

Pipe directly into pbcopy for instant copy:

pc() { p "$@" | tee /dev/tty | pbcopy }

Enter fullscreen mode Exit fullscreen mode

Now pc git squash last 3 commits prints the command and copies it.

Pipe straight into eval if you trust it (don't):

pe() { eval "$(p "$@")" }

Enter fullscreen mode Exit fullscreen mode

I have pc but not pe. Auto-executing model output is a bad habit even when it's almost always right.

why this beats the chat UI for short questions

Action Chat UI p
Switch context yes no
Round-trip latency ~3-5s + UI ~1-2s
Output format markdown, prose bare line
Copy command select + copy already in scrollback
Session pollution yes no (--no-session)

For anything longer than a paragraph the chat UI is still better. For "what's the syntax for X", terminal wins every time.

the meta-lesson

The friction between "I have a question" and "I have an answer" is mostly UI, not model latency. A 7-line shell function removed almost all of it.