One-shot mode lets you use Opsh without entering the interactive REPL. Pass your request as a quoted argument and Opsh generates, displays, and — after your confirmation — runs the command, then exits. This makes Opsh easy to use inline, in scripts, or from keyboard shortcuts.
Basic usage
Pass your request as a quoted argument to opsh:
opsh "list all files modified today"
Opsh generates the appropriate command, shows it with a risk level and explanation, and asks for confirmation before running it.
Examples
opsh "list all files modified today"
opsh "find all .log files larger than 10MB"
opsh --print-only "delete all .tmp files in /var"
Exit codes
| Code | Meaning |
|---|
0 | Command ran successfully, or you cancelled at the confirmation prompt |
1 | Command was blocked (matched a catastrophic pattern) or an error occurred |
Flags
--print-only
Preview the generated command without running it. Opsh displays the command and explanation, then exits without executing anything:
opsh --print-only "delete all .tmp files in /var"
This is useful when you want to check what Opsh would generate before committing to it, or when you’re building automation and want to audit commands first.
--shell
Override shell detection for the session. Opsh normally detects your current shell automatically, but you can force it to generate commands for a specific shell:
opsh --shell zsh "set an environment variable for this session"
opsh --shell bash "list all running processes"
Accepted values are zsh and bash.
Using one-shot mode in scripts and automation
One-shot mode is well-suited for automation workflows because it exits cleanly after each command. You can capture the exit code to handle success and failure:
opsh "compress the logs directory" && echo "Done" || echo "Command failed or was blocked"
You can also combine it with --print-only to preview commands in a CI or review workflow without executing anything.
When Opsh is not running in a TTY (for example, in a script or pipeline), it skips the interactive confirmation prompt and proceeds directly with the default action. Review your confirmByDefault setting in your configuration before using one-shot mode in automated contexts.