Skip to content

Commit d737a28

Browse files
committed
Add usage help, markdown formatting support, and fix command extraction for ask() and cmd() functions
1 parent 7b84db2 commit d737a28

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

.zshrc

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,20 +423,34 @@ fi
423423

424424
# Generic helper to ask an LLM about anything
425425
ask() {
426+
if [ $# = 0 ]; then
427+
echo "usage: ask <some question>"
428+
return 1
429+
fi
426430
if ! _has llm; then
427431
echo "llm tool not installed, run 'uv tool install llm'"
428432
return
429433
fi
430-
llm -s "We are on the command line for a system identified as $(uname -a). Answer the following question. Be brief and concise." "$*"
434+
local formatter=cat
435+
if _has glow; then
436+
formatter=glow
437+
elif _has md2term; then
438+
formatter=md2term
439+
fi
440+
llm -s "We are on the command line for a system identified as \`$(uname -a)\`. Answer the following question. Be brief and concise." "$*" | $formatter
431441
}
432442

433443
# AI helper for command line syntax, like "list subprocesses of pid 1234"
434444
cmd() {
445+
if [ $# = 0 ]; then
446+
echo "usage: cmd <some command description>"
447+
return 1
448+
fi
435449
if ! _has llm; then
436450
echo "llm tool not installed, run 'uv tool install llm'"
437451
return
438452
fi
439-
local cmd=(llm "We are on the command line for a system identified as $(uname -a). Show me a macOS command line comand for the following in a code block. Be brief and concise." "$*")
453+
local cmd=$(llm -x -s "We are on the command line for a system identified as \`$(uname -a)\`. Show me a command line comand for the following in a code block. Be brief and concise." "$*")
440454
echo -e "\n\x1b[32m$cmd\x1b[0m\n"
441455
echo -n "$cmd" | pbcopy
442456
}
@@ -580,7 +594,6 @@ ggg() {
580594
git status && \
581595
hr committing && \
582596
local msg=$(llm -x -s 'Summarize this git diff and produce a single sentence in a code block we can use for a commit message' -f <(git diff ; git diff --cached) | tr -d '\n') && \
583-
echo "$msg" && \
584597
git commit -m "$msg" && \
585598
hr results && \
586599
git --no-pager quicklog && \

0 commit comments

Comments
 (0)