git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Andreas Zeidler <az@zitc.de>
Cc: git@vger.kernel.org, gitster@pobox.com
Subject: Re: bash completion of "addable" files for `git add`
Date: Fri, 9 Nov 2012 11:27:50 -0500	[thread overview]
Message-ID: <20121109162750.GC19725@sigill.intra.peff.net> (raw)
In-Reply-To: <5E69B894-C392-4DD5-A4F1-723DA1A3D059@zitc.de>

On Fri, Nov 09, 2012 at 02:22:27PM +0100, Andreas Zeidler wrote:

> so here's a patch adding bash completion on `git add` for modified,
> updated and untracked files.  i've also set up a pull request — before
> i found `Documentation/SubmittingPatches`.  fwiw, it's at
> https://github.com/git/git/pull/29

Please put cover letter material like this after the "---" divider, or
include a "-- >8 --" scissors line before your commit. Either helps "git
am" realize which content should go into the commit message.

> From cbac6caee7e788569562cb7138eb698cc46a1b8f Mon Sep 17 00:00:00 2001
> From: Andreas Zeidler <az@zitc.de>
> Date: Fri, 9 Nov 2012 13:05:43 +0100

Please omit these lines, as they are redundant with your email header.

> Subject: [PATCH] add bash completion for "addable" files

This one is useful, but it would be even better if it were the subject
of your email. :)

> +__git_addable ()
> +{
> +	local dir="$(__gitdir)"
> +	if [ -d "$dir" ]; then
> +		git --git-dir="$dir" status --short --untracked=all |\
> +			egrep '^.[UM?] ' | sed 's/^.. //'
> +		return
> +	fi
> +}

You would want to use the stable, scriptable "--porcelain" output, so
the completion is not broken by future changes to the "--short" format.
However, I do not think using "git status" is the best option. It
computes three things:

  1. The diff between HEAD and index.

  2. The diff between index and working tree.

  3. The list of untracked files.

But you only care about (2) and (3), so you are wasting time computing
(1).  I think the list you want could be generated with:

  git diff-files --name-only
  git ls-files --exclude-standard -o

and then you do not need to worry about grep or sed at all.

> @@ -810,6 +820,11 @@ _git_add ()
>  			--ignore-errors --intent-to-add
>  			"
>  		return
> +		;;
> +	*)
> +		__gitcomp "$(__git_addable)"
> +		return
> +		;;

I think you'd want to use __gitcomp_nl to handle filenames with spaces.

Speaking of which, the output of status (or of the commands I mentioned)
may have quoting applied to pathnames. I think that is not something we
handle very well right now in the completion, so it may not be worth
worrying about for this particular patch.

Other than those comments, I think the intent of your patch makes a lot
of sense.

-Peff

      reply	other threads:[~2012-11-09 16:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-09 13:22 bash completion of "addable" files for `git add` Andreas Zeidler
2012-11-09 16:27 ` Jeff King [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20121109162750.GC19725@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=az@zitc.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).