Skip to content

Instantly share code, notes, and snippets.

@claytonchew
Last active June 1, 2026 01:46
Show Gist options
  • Select an option

  • Save claytonchew/3eb926dfa2354e13f35d855b21e92bfc to your computer and use it in GitHub Desktop.

Select an option

Save claytonchew/3eb926dfa2354e13f35d855b21e92bfc to your computer and use it in GitHub Desktop.
natural language to bash command with opencode (using free model)
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'
@claytonchew

Copy link
Copy Markdown
Author

Example Usage:

✨ Outputted command goes into your clipboard automatically.

$ pls ssh to root@192.168.0.11 using my ssh key "~/.ssh/mykey"
ssh -i ~/.ssh/mykey root@192.168.0.11

$ pls list all process running on node
ps aux | grep -I node

$ pls find file that contains SOME_VAR
grep -rl 'SOME_VAR' .

$ pls tail -f mylog filter line contains "192.168.0.11"
tail -f mylog | grep 192.168.0.11

$ pls replace '192.168.0.11' to '192.168.0.88' in ./host
sed -i '' 's/192\.168\.0\.11/192.168.0.88/g' ./host

$ pls docker build Dockerfile in this project with image name myapp
docker build -t myapp -f Dockerfile .

πŸ“– Pass in --explain anywhere in your prompt for explanation

$ pls docker build Dockerfile in this project with image name myapp --explain

This command builds a Docker image from the `Dockerfile` in the current directory:

docker build -t myapp -f Dockerfile .

- `-t myapp` tags the resulting image with the name `myapp`
- `-f Dockerfile` explicitly points to the `Dockerfile` (usually optional if it's named `Dockerfile` in the root; often omitted)
- `.` sets the build context to the current directory (required β€” tells Docker where to find files referenced in `COPY`/`ADD` instructions)

If the `Dockerfile` is actually at the root of the project and named `Dockerfile` (common convention), you can simplify to:

docker build -t myapp .

Docker automatically looks for `./Dockerfile` when no `-f` flag is given.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment