opencode icon indicating copy to clipboard operation
opencode copied to clipboard

fix: enable shell alias expansion in ! command

Open Zeko369 opened this issue 1 month ago • 1 comments

Summary

Fixes shell aliases not working when using the ! command prefix (e.g., ! g status where g is aliased to git).

Closes #4351

Problem

Shell aliases weren't being expanded because:

  1. In non-interactive shells, alias expansion is disabled by default in both zsh and bash
  2. Even after enabling alias expansion with shopt -s expand_aliases (bash), the command was already parsed before the aliases were loaded

Solution

  • Add shopt -s expand_aliases for bash to enable alias expansion (works in ZSH without it)
  • Wrap the command in eval to defer parsing until after aliases are loaded
  • Use JSON.stringify to properly escape the command string

Zeko369 avatar Dec 16 '25 10:12 Zeko369

@Zeko369 In theory, this would be fantastic! My bash/fish aliases are burned into my muscle memory by now, I have to constantly remind myself that they don't work in opencode's Shell mode and shake my fist ruefully at the wasted extra keystrokes (who wants to tire their fingers out typing git status when my aliases should just let me just type gs?).

Looking at the diff, though, it doesn't look like this is going to work properly for fish/zsh/nu users (or probably for Windows who use Powershell either, I guess? Can't test, no Windows here). Is there anything we can do about that?

ariane-emory avatar Dec 16 '25 11:12 ariane-emory

Thank you @Zeko369

rekram1-node avatar Dec 16 '25 17:12 rekram1-node