Skip to content

fix: enable shell alias expansion in ! command - #5621

Merged
rekram1-node merged 1 commit into
anomalyco:devfrom
Zeko369:fix/shell-aliases-expansion
Dec 16, 2025
Merged

rekram1-node merged 1 commit into
anomalyco:devfrom
Zeko369:fix/shell-aliases-expansion

Conversation

@Zeko369

@Zeko369 Zeko369 commented Dec 16, 2025 •

Copy link
Copy Markdown
Contributor

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

Enable alias expansion for zsh and bash when running shell commands via
the ! prefix. Previously, aliases weren't expanded because the command
was parsed before aliases were loaded.

The fix:
- Use eval to defer command parsing until after aliases are loaded
- Add 'shopt -s expand_aliases' for bash (required for alias expansion)
- Use JSON.stringify for proper escaping of the command string

Closes anomalyco#4351
@Zeko369
Zeko369 force-pushed the fix/shell-aliases-expansion branch from a3676c3 to c3a87d0 Compare December 16, 2025 10:11
@ariane-emory

ariane-emory commented Dec 16, 2025 •

Copy link
Copy Markdown
Contributor

@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?

@rekram1-node
rekram1-node merged commit c294402 into anomalyco:dev Dec 16, 2025
3 checks passed
@rekram1-node

Copy link
Copy Markdown
Collaborator

Thank you @Zeko369

nalin-singh pushed a commit to nalin-singh/opencode that referenced this pull request Dec 17, 2025
Rwanbt pushed a commit to Rwanbt/unifia that referenced this pull request May 5, 2026
AIALRA-0 pushed a commit to AIALRA-0/opencode-turn-engine that referenced this pull request Jun 10, 2026
Rwanbt pushed a commit to Rwanbt/unifia that referenced this pull request Jun 14, 2026
meSingh pushed a commit to meSingh/opencode that referenced this pull request Sep 6, 2026
androidand pushed a commit to androidand/opencode-skein that referenced this pull request Sep 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shell ! command does not honour my local aliases

3 participants