7

I'd like to use diff as described here and in the documentation I see when I type man diff. However, when I type diff, what I get is this:

~ ❯❯❯ diff
usage: git diff --no-index <path> <path>

Similarly when I try to use diff, I get git errors because -rq is supported in man diff but not by git diff:

~ ❯❯❯ diff -rq ~/ ~/Desktop
fatal: invalid diff option/value: -rq

I'm using Prezto and hub which both help with git productivity, but neither creates an alias that doesn't at least start with g, as far as I can tell.

I've run a few scripts like this to try to find something that's defining diff to git diff but to no avail.

How do I fix this/find what's causing it/override it?

Edit

Ran type diff:

diff is a shell function
diff is /usr/bin/diff
7
  • Run type diff and post the output. Commented Dec 11, 2015 at 23:06
  • 2
    And I suspect it will be github.com/sorin-ionescu/prezto/blob/master/modules/utility/… Commented Dec 11, 2015 at 23:09
  • @MichaelHomer Added. That does look right to me. Commented Dec 11, 2015 at 23:11
  • I don't know how you tell prezto not to do that, but worst case you can just hack it out. Commented Dec 11, 2015 at 23:13
  • 1
    IN FACT! I ran brew install colordiff and now diff runs colordiff, which is an actual diff-based thing. Commented Dec 11, 2015 at 23:33

3 Answers 3

9

This seems to be from prezto defining a function overriding diff. It may well have a way of disabling that, but I don't know what it is (but ericbn does!). You have a few options:

  • /usr/bin/diff or command diff will both run the diff command, rather than the function.
  • unset -f diff will remove the diff function. You could put that in your shell configuration.
  • As you've found, if colordiff is installed it will be used in preference to git diff by the function.
  • Finally, you can remove or rename the function from that file itself.

This really seems like a misfeature in prezto.

1
  • 1
    certainly a good example of the ills of global scope and naming collisions Commented Dec 12, 2015 at 0:39
2

I would use an function like this

$ diffit () {
command diff "$@"
}

A function over an alias as there are parameters

Usage: diffit file1 file2

You could put it in your .bashrc
Personally I keep my collection of functions in .bash_functions and in .bashrc I have

test -f ~/.bash_functions.sh && . $_
1
  • 1
    Just make it command diff "$@". Commented Dec 12, 2015 at 2:03
1

As @MichaelHomer answered, this is a prezto function, part of the utility module documented in https://github.com/sorin-ionescu/prezto/tree/master/modules/utility. The way to disable this is:

To disable diff highlighting, add the following line to zpreztorc:

zstyle ':prezto:module:utility:diff' color 'no'

Or installing colordiff would also make the custom function call it instead of git diff, as the purpose of the custom prezto diff is:

  • diff highlights diff output (requires colordiff or Git).

You must log in to answer this question.

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