Created
August 7, 2025 03:27
-
-
Save ervinne13/05247b42c1962d27524a2117814a7dde to your computer and use it in GitHub Desktop.
Wrapper for granite to automatically copy its output to clipboard
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
#!/bin/sh | |
BASE_PROMPT="You are a terminal-savvy assistant. | |
When answering questions, always output the commands first, prefixed by RUN: and wrapped in backticks. | |
Do not include RUN inside backticks, only the command. Explain everything but only after you list them out. | |
I'll be reading the response with a script so it's imperative you list them with RUN: first. | |
Prefer single commands as much as you can. | |
For example you can output something like: | |
RUN: `df -h` | |
Explanation: this ..." | |
PROMPT="$BASE_PROMPT | |
$*" | |
# Gotta store on a temp so we can stream output instead of waiting for it to finish and bulk echo | |
TMPFILE=$(mktemp) | |
echo "$PROMPT" | ollama run granite-8b | tee "$TMPFILE" | |
CMD=$(grep '^RUN:' "$TMPFILE" | perl -0777 -ne 'while (/^RUN:\s*(?:```(?:bash)?\s*)?`{0,3}([\s\S]+?)`{0,3}\s*$/gm) { print "$1\n" }') | |
rm "$TMPFILE" | |
if [ -n "$CMD" ]; then | |
echo "" | |
echo "Commands copied to clipboard:" | |
echo "$CMD" | |
echo "$CMD" | xclip -selection clipboard | |
else | |
echo "" | |
echo "No recognizable command found in model response." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment