Last active
June 1, 2026 01:46
-
-
Save claytonchew/3eb926dfa2354e13f35d855b21e92bfc to your computer and use it in GitHub Desktop.
natural language to bash command with opencode (using free model)
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
| pls() { | |
| local input escaped output command | |
| printf -v input '%s ' "$@" | |
| escaped=$(printf '%q ' "$@") | |
| output=$( | |
| opencode run \ | |
| --title "to-bash: ${escaped}" \ | |
| --agent subagent \ | |
| --model opencode/deepseek-v4-flash-free \ | |
| --variant max \ | |
| "When the user describes a shell action in natural language, respond with the appropriate bash command(s) wrap between <command></command> tags. Example: <command>git checkout main</command>. Be concise: just output the command(s), no explanation unless --explain is provided in this case do not use <command></command> tag. Output the most direct, idiomatic bash command. Prefer One-liners, if multiple are genuinely needed, chain with &&. Do not provide any further instruction, assume your response will be piped and executed immediately. User message starts now: ${escaped}" \ | |
| 2>/dev/null | | |
| grep -v '^>' | | |
| grep -v '^$' | |
| ) | |
| command=$(printf '%s\n' "$output" | | |
| sed -n 's/.*<command>\(.*\)<\/command>.*/\1/p') | |
| if [ -n "$command" ]; then | |
| printf '%s' "$command" | pbcopy | |
| printf '%s\n' "$command" | |
| else | |
| printf '%s\n' "$output" | |
| fi | |
| } | |
| alias pls='noglob pls' |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example Usage:
β¨ Outputted command goes into your clipboard automatically.
π Pass in
--explainanywhere in your prompt for explanation