# [PATCH/RFC] bash: add --word-diff option to diff auto-completion

5 messages from 2011-09-13 to 2011-09-16. Participants: Jonathan Nieder, SZEDER Gábor, Rodrigo Rosenfeld Rosas.
Thread: https://gitlist.dev/t/28382

## Jonathan Nieder, 2011-09-13 19:14

Subject: [PATCH/RFC] bash: add --word-diff option to diff auto-completion
Message-ID: <20110913191448.GC14917@elie>
URL: https://gitlist.dev/e/20110913191448.GC14917%40elie
In-Reply-To: <4E6FA541.7000100@yahoo.com.br>

```
From: Rodrigo Rosenfeld Rosas <rr.rosas@gmail.com>
Date: Tue, 13 Sep 2011 15:24:38 -0300

Add "--word-diff" to diff completion, since this is a common
desired option when looking at diffs.

Signed-off-by: Rodrigo Rosenfeld Rosas <rr.rosas@gmail.com>
---
Hi Gábor,

Here's a patch.  What do you think?

I was thinking it would be nice to complete --word-diff-regex, too,
and to be able to do

	git diff --color-words=<TAB>
	git diff --word-diff=<TAB>

but I couldn't find any examples of the latter to crib from, so I've
left the patch unmangled except for stealing a patch description from
a separate email.

Rodrigo Rosenfeld Rosas wrote:

> I use Thunderbird, but couldn't find all options as instructed in 'git help
> format-patch'.

Indeed, sending patches unmangled seems to be a common difficult step
when starting to contribute to projects like linux and git.  I wonder
if it would make sense to include some sort of
patch-sending-reviewing-tweaking-and-receiving tutorial to point to in
the documentation.

Thanks for keeping the completion code in good shape.
Jonathan

 contrib/completion/git-completion.bash |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 8648a36..f4aaffe 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1300,7 +1300,7 @@ _git_describe ()
 
 __git_diff_common_options="--stat --numstat --shortstat --summary
 			--patch-with-stat --name-only --name-status --color
-			--no-color --color-words --no-renames --check
+			--no-color --color-words --word-diff --no-renames --check
 			--full-index --binary --abbrev --diff-filter=
 			--find-copies-harder
 			--text --ignore-space-at-eol --ignore-space-change
-- 
1.7.5.4

```

## SZEDER Gábor, 2011-09-13 23:29

Subject: Re: [PATCH/RFC] bash: add --word-diff option to diff auto-completion
Message-ID: <20110913232941.GC2078@goldbirke>
URL: https://gitlist.dev/e/20110913232941.GC2078%40goldbirke
In-Reply-To: <20110913191448.GC14917@elie>

```
Hi,


On Tue, Sep 13, 2011 at 02:14:48PM -0500, Jonathan Nieder wrote:
> From: Rodrigo Rosenfeld Rosas <rr.rosas@gmail.com>
> Date: Tue, 13 Sep 2011 15:24:38 -0300
> 
> Add "--word-diff" to diff completion, since this is a common
> desired option when looking at diffs.
> 
> Signed-off-by: Rodrigo Rosenfeld Rosas <rr.rosas@gmail.com>
> ---
> Hi Gábor,
> 
> Here's a patch.  What do you think?

Looks obviously good to me, ...

> I was thinking it would be nice to complete --word-diff-regex, too,
> and to be able to do
> 
> 	git diff --color-words=<TAB>
> 	git diff --word-diff=<TAB>

... but yeah, there is room for while-at-its ;)

The completion script currently only offers --color-words but not
--color-words=.  This is sort of OK, because --color-words' parameters
are optional.  However, in several cases the completion script offers
both --option and --option= to indicate that it takes an optional
parameter, see e.g.

  diff --dirstat --dirstat-by-file
  commit --untracked-files
  format-patch --thread
  init --shared
  log --decorate

(But we don't do this in all such cases, see e.g. diff --stat --color
or log --branches --tags --remotes.)

So I think it's fine to offer both --color-words and --color-words=,
and both --word-diff and --word-diff=.

> but I couldn't find any examples of the latter to crib from

I'm not sure what you mean by git diff --color-words=<TAB>, because it
takes a regexp.  Or is it just too late here and I'm missing something
obvious?

Completing the mode for --word-diff=<TAB> is a good idea, but c'mon,
there are plenty of examples ;)  Have a look at _git_am(),
_git_format_patch(), or _git_init() for something easy, and
_git_commit(), _git_log(), or _git_notes() for something fancy.

Note that --word-diff= is also valid for log and shortlog, so the same
can be done there, too.


Best,
Gábor

```

## SZEDER Gábor, 2011-09-13 23:37

Subject: Re: [PATCH/RFC] bash: add --word-diff option to diff auto-completion
Message-ID: <20110913233712.GE2078@goldbirke>
URL: https://gitlist.dev/e/20110913233712.GE2078%40goldbirke
In-Reply-To: <20110913232941.GC2078@goldbirke>

```
On Wed, Sep 14, 2011 at 01:29:41AM +0200, SZEDER Gábor wrote:
> Or is it just too late here and I'm missing something
> obvious?
> 
> Completing the mode for --word-diff=<TAB> is a good idea, but c'mon,
> there are plenty of examples ;)  Have a look at _git_am(),
> _git_format_patch(), or _git_init() for something easy, and
> _git_commit(), _git_log(), or _git_notes() for something fancy.
> 
> Note that --word-diff= is also valid for log and shortlog, so the same
> can be done there, too.

Not shortlog, show.  It's definitely too late... ;)

```

## Rodrigo Rosenfeld Rosas, 2011-09-16 15:56

Subject: Re: [PATCH/RFC] bash: add --word-diff option to diff [AND --set-upstream TO push] auto-completion
Message-ID: <4E737199.1000107@yahoo.com.br>
URL: https://gitlist.dev/e/4E737199.1000107%40yahoo.com.br
In-Reply-To: <20110913233712.GE2078@goldbirke>

```
While on the topic, it would also be interesting to add "--set-upstream" 
to "git push" autocompletion. Don't you agree?

Cheers, Rodrigo.

Em 13-09-2011 20:37, SZEDER Gábor escreveu:
> On Wed, Sep 14, 2011 at 01:29:41AM +0200, SZEDER Gábor wrote:
>> Or is it just too late here and I'm missing something
>> obvious?
>>
>> Completing the mode for --word-diff=<TAB>  is a good idea, but c'mon,
>> there are plenty of examples ;)  Have a look at _git_am(),
>> _git_format_patch(), or _git_init() for something easy, and
>> _git_commit(), _git_log(), or _git_notes() for something fancy.
>>
>> Note that --word-diff= is also valid for log and shortlog, so the same
>> can be done there, too.
>
> Not shortlog, show.  It's definitely too late... ;)
>
>

```

## Jonathan Nieder, 2011-09-16 20:47

Subject: Re: [PATCH/RFC] bash: add --word-diff option to diff [AND --set-upstream TO push] auto-completion
Message-ID: <20110916204722.GD4683@elie>
URL: https://gitlist.dev/e/20110916204722.GD4683%40elie
In-Reply-To: <4E737199.1000107@yahoo.com.br>

```
Rodrigo Rosenfeld Rosas wrote:

> While on the topic, it would also be interesting to add "--set-upstream" to
> "git push" autocompletion. Don't you agree?

Yes, of course.

```
