opencode icon indicating copy to clipboard operation
opencode copied to clipboard

[FEATURE] Tab completion support in shell mode (! command)

Open everhopingandwaiting opened this issue 4 days ago • 1 comments

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

  1. Type ! to enter shell mode
  2. Type commands manually without any auto-completion assistance
  3. 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:

  1. Command completion: Type gi + Tab → completes to git
  2. Path completion: Type /usr/lo + Tab → completes to /usr/local/
  3. Argument completion: Type git ch + Tab → completes to git checkout
  4. History completion: Up/down arrows or Ctrl+R for command history
  5. 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/path with Tab completion
  • Development commands: npm run dev, cargo build, make install with 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

  1. Lightweight approach: Basic command/path completion using built-in knowledge
  2. Shell integration: Interface with actual shell completion (bash/zsh/fish)
  3. 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

  1. Phase 1: Basic command and path completion
  2. Phase 2: Command-specific argument completion
  3. Phase 3: History and context-aware completion
  4. 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

everhopingandwaiting avatar Jan 11 '26 05:01 everhopingandwaiting