Skip to content

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

@everhopingandwaiting

Description

@everhopingandwaiting

Feature hasn't been suggested before.

  • 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

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

Metadata

Metadata

Assignees

Labels

discussionUsed for feature requests, proposals, ideas, etc. Open discussionopentuiThis relates to changes in v1.0, now that opencode uses opentui

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions