[FEATURE] Tab completion support in shell mode (! command)
Feature hasn't been suggested before.
- [x] I have verified this feature I'm about to request hasn't been suggested before.
Describe the enhancement you want to request
Description
Problem
Currently, when using the ! command to enter shell mode in opencode TUI, there is no Tab auto-completion support for shell commands. Users must manually type complete commands, arguments, and file paths, which significantly reduces efficiency and user experience, especially for complex commands or long file paths.
Current Behavior
- Type
!to enter shell mode - Type commands manually without any auto-completion assistance
- No Tab completion for:
- Command names (git, npm, ls, etc.)
- Command arguments and flags
- File paths and directory names
- Environment variables
- Command history
Expected Behavior
Shell mode should provide Tab auto-completion similar to standard shell environments:
-
Command completion: Type
gi+ Tab → completes togit -
Path completion: Type
/usr/lo+ Tab → completes to/usr/local/ -
Argument completion: Type
git ch+ Tab → completes togit checkout - History completion: Up/down arrows or Ctrl+R for command history
- Context-aware suggestions: Based on current directory and previous commands
Use Cases
-
Git operations:
git checkout fea+ Tab → completes branch names -
File operations:
cp /long/path/to/file /another/long/pathwith Tab completion -
Development commands:
npm run dev,cargo build,make installwith completion - System administration: Complex command chains with proper path completion
- Learning: Discover available commands and options through completion suggestions
Proposed Implementation
1. Basic Command Completion
// Pseudo-implementation
const availableCommands = ['git', 'npm', 'cargo', 'make', 'ls', 'cd', 'cp', 'mv'];
const userInput = 'gi';
const suggestions = availableCommands.filter(cmd => cmd.startsWith(userInput));
// Result: ['git']
2. Path Completion Integration
- Leverage existing opencode file system APIs
- Use
@file reference autocomplete logic as foundation - Extend to support shell-style path completion
3. Shell Integration Options
- Lightweight approach: Basic command/path completion using built-in knowledge
- Shell integration: Interface with actual shell completion (bash/zsh/fish)
- Hybrid approach: Start with basic, evolve to shell integration
4. Configuration Options
{
"tui": {
"shell_completion": {
"enabled": true,
"style": "bash", // bash, zsh, fish, basic
"case_sensitive": false,
"show_hidden_files": true,
"command_history_size": 1000
}
}
}
Technical Considerations
1. Cross-Platform Support
- Linux: bash/zsh completion
- macOS: bash/zsh completion
- Windows: PowerShell/cmd completion
- Fallback to basic completion for unsupported shells
2. Performance
- Async completion to avoid blocking UI
- Caching of common commands and paths
- Lazy loading of completion data
3. Security
- Sanitize completion suggestions
- Respect file system permissions
- Safe handling of special characters
Benefits
- Improved productivity: Faster command entry with fewer typos
- Better user experience: Familiar shell-like interaction
- Reduced context switching: Stay in opencode while getting shell convenience
- Learning aid: Discover commands and options through completion
- Accessibility: Helpful for users with typing difficulties
Implementation Priority
- Phase 1: Basic command and path completion
- Phase 2: Command-specific argument completion
- Phase 3: History and context-aware completion
- Phase 4: Shell-native completion integration
Related Issues
- Issue #6975: "tui: autocomplete: expand directory on Tab, select on Enter" (file reference completion)
- Issue #4280: "bash completions" (CLI command completion)
- Issue #6248: "Can't when in shell mode select options" (shell mode interaction issues)
Operating System
All platforms (Linux, macOS, Windows)
Terminal
All supported terminals (with platform-specific optimizations)
OpenCode Version
Latest version (1.x)
Additional Context
This feature would significantly enhance the shell mode usability by bringing standard shell conveniences into the opencode environment. The implementation can start simple and evolve based on user feedback and usage patterns.
The existing file reference autocomplete (@ command) provides a solid foundation that can be extended for shell mode completion.
References
- Shell completion documentation: https://opencode.ai/docs/tui#bash-commands
- File reference completion: https://opencode.ai/docs/tui#file-references
- Related autocomplete work: PR #6975