3

On MacOS I am using oh-my-zsh with no customization that I know of.

Autocompletion is mostly working quite nicely and I'm very happy with it. But for some reason the diff command is different.

��  ls file<TAB>
file1  file2
➜  diff file1 file<TAB>  # Rings bell and no completion
➜  diff file1 <TAB>  # Gives me a "-" completion
➜  diff file1 -<TAB>
-b  -- skip trailing white spaces
-c  -- output a context diff
-e  -- output an ed script
-f  -- output a reversed ed script
-r  -- recursively compare subdirectories

So diff seems unaware that you can provide a second argument as the second file to diff, and it only seems to only accept command options as the second thing.

Any ideas what is happening or how to fix this?

In general, is there an easy way to configure to fully disable the smart completion for a particular command? I did compdef _files diff and that worked in that shell but not in subsequent new shells.

5
  • 1
    I can't reproduce this even with an uncustomized oh-my-zsh, so it has to be something peculiar in your configuration or in your system, or maybe a specific buggy version of something. What does type diff say? And echo $_comps[diff]? What version of macOS? If you can't resolve this, use ^X? instead of TAB to complete and upload the trace output file. Commented Jan 1, 2023 at 17:28
  • 2
    Bingo, thanks!! type diff shows diff aliased to diff --color. I didn't even realize this and must have made this alias eons ago. Removing that alias fixed the issue and lesson learned on diagnosing these kinds of issues. Thanks again. The git support in oh-my-zsh is incredible and changed my life (for the better). Commented Jan 1, 2023 at 21:37
  • @Gilles'SO-stopbeingevil' - digger deeper I discovered that ohmyzsh is responsible for the alias here: github.com/ohmyzsh/ohmyzsh/blob/…. So this alias is intended and presumably works for most people but not me. Here's the debug output: gist.github.com/taldcroft/d33c81814f14bcc38551b2777ec304bd. Commented Jan 2, 2023 at 11:23
  • 2
    There's an open issue for it here: github.com/ohmyzsh/ohmyzsh/issues/11416
    – nofinator
    Commented Jan 5, 2023 at 17:03
  • For what it is worth, I have run into a similar issue without oh-my-zsh which is unrelated to the alias issue because I do not have diff defined as an alias. For me, the behavior is that the completion works fine only if I do not specify the -u argument. When I do, the second parameter to diff is not auto-completed. Commented May 24 at 14:41

2 Answers 2

1

This is due to a bug in oh my zsh that was fixed for a bit on January 25, 2023 but broken again as of March 3, 2023

I've added a comment to the original issue highlighting this regression and attempted to fix it locally myself but ran into issues. If oh my zsh team fixes this bug, I will update this answer.

1

The issue is because oh-my-zsh defines alias diff='diff --color', but the diff command from macOS does not support such a flag. You can see that by doing /usr/bin/diff --help.

So the color flag may effectively be acting as the first filename argument.

A workaround is to install the GNU diff, which supports the flag color. With brew:

brew install diffutils

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .