Created
February 9, 2026 12:37
-
-
Save mhdcodes/608df7377ab5a9dcc90ef5edd54817f6 to your computer and use it in GitHub Desktop.
Improve clipboard text writing with Groq AI.
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/bash | |
| # Configuration | |
| API_KEY="${GROQ_API_KEY}" # Set via environment variable or hardcode | |
| MODEL="llama-3.1-8b-instant" | |
| # Read current clipboard | |
| TEXT=$(xclip -o -selection clipboard 2>/dev/null) | |
| # Exit if clipboard is empty | |
| if [ -z "$TEXT" ]; then | |
| notify-send "AI Text Enhancement" "Clipboard is empty" | |
| exit 0 | |
| fi | |
| # Escape text for JSON | |
| TEXT_ESCAPED=$(echo "$TEXT" | jq -Rs .) | |
| # Make API request to Groq | |
| RESPONSE=$(curl -s https://api.groq.com/openai/v1/chat/completions \ | |
| -H "Content-Type: application/json" \ | |
| -H "Authorization: Bearer $API_KEY" \ | |
| -d "{ | |
| \"messages\": [ | |
| { | |
| \"role\": \"system\", | |
| \"content\": \"You rewrite user text with correct grammar and clearer wording, Do not add any fluff or commentary. Output only the revised text.\" | |
| }, | |
| { | |
| \"role\": \"user\", | |
| \"content\": $TEXT_ESCAPED | |
| } | |
| ], | |
| \"model\": \"$MODEL\", | |
| \"temperature\": 0.3, | |
| \"max_completion_tokens\": 2048, | |
| \"stream\": false | |
| }") | |
| # Extract enhanced text from response | |
| IMPROVED=$(echo "$RESPONSE" | jq -r '.choices[0].message.content') | |
| # Check if enhancement succeeded | |
| if [ -n "$IMPROVED" ] && [ "$IMPROVED" != "null" ]; then | |
| echo "$IMPROVED" | xclip -selection clipboard | |
| notify-send "AI Text Enhancement" "Clipboard is ready" | |
| else | |
| ERROR=$(echo "$RESPONSE" | jq -r '.error.message // "Unknown error"') | |
| notify-send "AI Enhancement Failed" "$ERROR" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment