Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
    
Angers you? Really? –  mattdm Mar 15 '11 at 19:36
1  
Umm. Yes? (6 more to go..) –  VxJasonxV Mar 15 '11 at 22:16
add comment

1 Answer 1

up vote 10 down vote accepted
$ 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)'
share|improve this answer
    
I started to notice $COLUMNS and was thinking something along the same lines. alias diff="diff -W ${COLUMNS}". I think I'd prefer to ask the shell rather than rely on the environment though. –  VxJasonxV Mar 15 '11 at 22:17
1  
tput considers $COLUMNS, stty -a, and the terminal description, using the first of those that has a meaningful value. eval $(resize) can be used to force them to be in sync with what the terminal thinks its size is. –  geekosaur Mar 15 '11 at 22:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.