Make diff Use Full Terminal Width in Side-by-Side Mode

diff()terminal

Most applications are smart about using the full width of the terminal available to them. My shell does, screen, vim, etc. However, diff in side-by-side mode (-y), does not. This angers me. It uses 126 character width, which is not even half of my 270 block width terminal.

Looking through the man page does not reveal anything particular about automatically adjusting the width, only manually specifying it via -W.

Is there perhaps a "hidden feature" of diff to allow it to automatically expand to the full width of the terminal?
Or;
What is the easiest path to automatically inserting -W <terminalsize> into my diff command whenever I run it?

I am under the assumption that automatically appending -W to everything couldn't hurt anything, because it will only ever mean "use $x columns", which is always what I want, whether I'm in side-by-side mode, or otherwise.

Best Answer

$ alias diff='diff -W $(( $(tput cols) - 2 ))'

ought to do it. You'll want to add it to ~/.bashrc as well.

The - 2 is mainly paranoia, in case something (embedded double-width Unicode?) expands enough to make the line wrap; if you want, you can just use

$ alias diff='diff -W $(tput cols)'
Related Question