djui / alias-tips

An oh-my-zsh plugin to help remembering those aliases you defined once
786 stars 50 forks source link

Unexpected "reveals" for non-aliases #55

Open yanok opened 3 years ago

yanok commented 3 years ago

I've found some unexpected "Alias for:" messages, especially while running particularly long commands:

$ echo longlonglonglonglonglonglong linelinelinelinelinelinelinelinelinelineline
Alias for: echo longlonglonglonglonglonglong linelinelinelinelinelinelinelinelinelinelin 
longlonglonglonglonglonglong linelinelinelinelinelinelinelinelinelineline

I believe this is because the second argument to the preexec hook can be trimmed and what we really want is to compare the command with the third argument, which is not trimmed.

Another issue is with export (maybe some other builtins too, but I've only seen export so far):

$ export TEST=x                                                                   
Alias for: export TEST=x  

This one is because expanded command for some reason has a trailing whitespace. I'm not sure, maybe this is actually a zsh bug, but we can easily workaround this by removing the trailing whitespace before doing comparison.

Would you be interested in PRs to fix that? Any objections to

  1. Using CMD_EXPANDED=$3 instead of CMD_EXPANDED=$2
  2. Removal trailing whitespace from CMD/CMD_EXPANDED?
djui commented 3 years ago

Yes, PR is welcome.

I am not sure I understand the

Using CMD_EXPANDED=$3 instead of CMD_EXPANDED=$2

part, but let's see in the PR if I get it.

(2) seems sensible.

yanok commented 3 years ago

Regarding CMD_EXPANDED=$3, from zsh doc (http://zsh.sourceforge.net/Doc/Release/Functions.html):

The actual command that will be executed (including expanded aliases) is passed in two different forms: the second argument is a single-line, size-limited version of the command (with things like function bodies elided); the third argument contains the full text that is being executed.

What I experience currently is long commands are falsely detected as aliases. I believe this is exactly because the second argument to the hook is size-limited.