All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] completion: add completer for status
@ 2013-06-24 17:22 Ramkumar Ramachandra
  2013-06-24 17:28 ` Ramkumar Ramachandra
  2013-06-28 10:29 ` SZEDER Gábor
  0 siblings, 2 replies; 9+ messages in thread
From: Ramkumar Ramachandra @ 2013-06-24 17:22 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 contrib/completion/git-completion.bash | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 6c3bafe..912fb98 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1695,6 +1695,32 @@ _git_stage ()
 	_git_add
 }
 
+_git_status ()
+{
+	case "$cur" in
+	--untracked-files=*)
+		__gitcomp "no normal all" "" "${cur##--untracked-files=}"
+		return
+		;;
+	--ignore-submodules=*)
+		__gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
+		return
+		;;
+	--column=*)
+		__gitcomp "always never auto column row plain dense nodense" "" "${cur##--column=}"
+		return
+		;;
+	--*)
+		__gitcomp "
+			--short --branch --long --porcelain
+			--untracked-files= --ignore-submodules= --ignored --column=
+			"
+		return
+		;;
+	esac
+	__git_complete_index_file
+}
+
 __git_config_get_set_variables ()
 {
 	local prevword word config_file= c=$cword
-- 
1.8.3.1.550.gd96f26e.dirty

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] completion: add completer for status
  2013-06-24 17:22 [PATCH] completion: add completer for status Ramkumar Ramachandra
@ 2013-06-24 17:28 ` Ramkumar Ramachandra
  2013-06-28 10:29 ` SZEDER Gábor
  1 sibling, 0 replies; 9+ messages in thread
From: Ramkumar Ramachandra @ 2013-06-24 17:28 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano

Ramkumar Ramachandra wrote:
> +       __git_complete_index_file

Um, that should be __git_complete_index_file "--cached", I think.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] completion: add completer for status
  2013-06-24 17:22 [PATCH] completion: add completer for status Ramkumar Ramachandra
  2013-06-24 17:28 ` Ramkumar Ramachandra
@ 2013-06-28 10:29 ` SZEDER Gábor
  2013-06-28 10:56   ` SZEDER Gábor
  1 sibling, 1 reply; 9+ messages in thread
From: SZEDER Gábor @ 2013-06-28 10:29 UTC (permalink / raw)
  To: Ramkumar Ramachandra; +Cc: Git List, Junio C Hamano

Hi,

On Mon, Jun 24, 2013 at 10:52:55PM +0530, Ramkumar Ramachandra wrote:
> Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
> ---
>  contrib/completion/git-completion.bash | 26 ++++++++++++++++++++++++++
>  1 file changed, 26 insertions(+)
> 
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 6c3bafe..912fb98 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -1695,6 +1695,32 @@ _git_stage ()
>  	_git_add
>  }
>  
> +_git_status ()
> +{
> +	case "$cur" in
> +	--untracked-files=*)
> +		__gitcomp "no normal all" "" "${cur##--untracked-files=}"
> +		return
> +		;;
> +	--ignore-submodules=*)
> +		__gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
> +		return
> +		;;
> +	--column=*)
> +		__gitcomp "always never auto column row plain dense nodense" "" "${cur##--column=}"
> +		return
> +		;;
> +	--*)
> +		__gitcomp "
> +			--short --branch --long --porcelain
> +			--untracked-files= --ignore-submodules= --ignored --column=

The parameter for '--untracked-files' '--ignore-submodules' and
'--column' is optional.  In such cases we usually list the option both
with and without the '=' as a reminder, e.g. look at 'git log's
'--decorate' and '--dirstat'.

> +			"
> +		return
> +		;;
> +	esac
> +	__git_complete_index_file

With or without this change we can't ask for the status of a certain
deleted file:

$ git rm version.h
rm 'version.h'
$ git status 
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       deleted:    version.h
#
$ git status v<TAB>
varint.c   varint.h   vcs-svn/   version.c  

I wonder whether there is some clever combination of options that
would make that possible?  I didn't find it.


Gábor

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] completion: add completer for status
  2013-06-28 10:29 ` SZEDER Gábor
@ 2013-06-28 10:56   ` SZEDER Gábor
  2013-06-28 11:26     ` SZEDER Gábor
  0 siblings, 1 reply; 9+ messages in thread
From: SZEDER Gábor @ 2013-06-28 10:56 UTC (permalink / raw)
  To: Ramkumar Ramachandra; +Cc: Git List, Junio C Hamano

On Fri, Jun 28, 2013 at 12:29:36PM +0200, SZEDER Gábor wrote:
> On Mon, Jun 24, 2013 at 10:52:55PM +0530, Ramkumar Ramachandra wrote:
> > Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
> > +	__git_complete_index_file
> 
> With or without this change we can't ask for the status of a certain
> deleted file:
> 
> $ git rm version.h
> rm 'version.h'
> $ git status 
> # On branch master
> # Changes to be committed:
> #   (use "git reset HEAD <file>..." to unstage)
> #
> #       deleted:    version.h
> #
> $ git status v<TAB>
> varint.c   varint.h   vcs-svn/   version.c  

Well, at least the deleted is there if I only remove it from the work
tree (i.e. use 'rm' instead of 'git rm'):

$ rm version.h
$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working
#   directory)
#
#       deleted:    version.h
#
no changes added to commit (use "git add" and/or "git commit -a")
$ git status v<TAB>
varint.c   varint.h   vcs-svn/   version.c  version.h  


Gábor

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] completion: add completer for status
  2013-06-28 10:56   ` SZEDER Gábor
@ 2013-06-28 11:26     ` SZEDER Gábor
  2013-06-28 13:20       ` Ramkumar Ramachandra
  0 siblings, 1 reply; 9+ messages in thread
From: SZEDER Gábor @ 2013-06-28 11:26 UTC (permalink / raw)
  To: Ramkumar Ramachandra; +Cc: Git List, Junio C Hamano

On Fri, Jun 28, 2013 at 12:56:01PM +0200, SZEDER Gábor wrote:
> On Fri, Jun 28, 2013 at 12:29:36PM +0200, SZEDER Gábor wrote:
> > On Mon, Jun 24, 2013 at 10:52:55PM +0530, Ramkumar Ramachandra wrote:
> > > Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
> > > +	__git_complete_index_file
> > 
> > With or without this change we can't ask for the status of a certain
> > deleted file:
> > 
> > $ git rm version.h
> > rm 'version.h'
> > $ git status 
> > # On branch master
> > # Changes to be committed:
> > #   (use "git reset HEAD <file>..." to unstage)
> > #
> > #       deleted:    version.h
> > #
> > $ git status v<TAB>
> > varint.c   varint.h   vcs-svn/   version.c  
> 
> Well, at least the deleted is there if I only remove it from the work
> tree (i.e. use 'rm' instead of 'git rm'):
> 
> $ rm version.h
> $ git status
> # On branch master
> # Changes not staged for commit:
> #   (use "git add/rm <file>..." to update what will be committed)
> #   (use "git checkout -- <file>..." to discard changes in working
> #   directory)
> #
> #       deleted:    version.h
> #
> no changes added to commit (use "git add" and/or "git commit -a")
> $ git status v<TAB>
> varint.c   varint.h   vcs-svn/   version.c  version.h  

Ok, how about this on top?


diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 912fb988..b68024c6 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1697,6 +1697,8 @@ _git_stage ()
 
 _git_status ()
 {
+	__git_has_doubledash && return
+
 	case "$cur" in
 	--untracked-files=*)
 		__gitcomp "no normal all" "" "${cur##--untracked-files=}"
@@ -1718,7 +1720,7 @@ _git_status ()
 		return
 		;;
 	esac
-	__git_complete_index_file
+	__git_complete_index_file "--with-tree=HEAD --cached --deleted"
 }
 
 __git_config_get_set_variables ()


In my cursory testing it seemed to do the right thing for deleted and
tracked files:

$ rm version.h
$ git rm version.c
rm 'version.c'
$ echo >varint.h
$ echo >v-added
$ git add v-added 
$ echo >v-untracked
$ git status 
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       new file:   v-added
#       deleted:    version.c
#
# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working
#   directory)
#
#       modified:   varint.h
#       deleted:    version.h
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       v-untracked
$ git status v
v-added    varint.c   varint.h   vcs-svn/   version.c  version.h

Note, however, that this doesn't offer untracked files (Ram's original
didn't do that either), but in case somebody really needs that he can
have it by using '--':

$ git status -- v
v-added      varint.c     varint.h     vcs-svn/     v-untracked


Best,
Gábor

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] completion: add completer for status
  2013-06-28 11:26     ` SZEDER Gábor
@ 2013-06-28 13:20       ` Ramkumar Ramachandra
  2013-06-28 14:03         ` Ramkumar Ramachandra
  2013-06-28 14:04         ` SZEDER Gábor
  0 siblings, 2 replies; 9+ messages in thread
From: Ramkumar Ramachandra @ 2013-06-28 13:20 UTC (permalink / raw)
  To: SZEDER Gábor; +Cc: Git List, Junio C Hamano

SZEDER Gábor wrote:
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 912fb988..b68024c6 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -1697,6 +1697,8 @@ _git_stage ()
>
>  _git_status ()
>  {
> +       __git_has_doubledash && return
> +

This line makes absolutely no sense to me.  When the case statement
fails to match anything (which it will, when a double-dash is
present), we'll use the __git_complete_index_file which is superior to
returning and falling back to the dumb zsh file listing, no?  As a
result, without that line,

  $ git status -- foo<TAB>

will complete fine when foo* isn't necessarily a file in the
filesystem, but something that our ls-files returns, no?

>         case "$cur" in
>         --untracked-files=*)
>                 __gitcomp "no normal all" "" "${cur##--untracked-files=}"
> @@ -1718,7 +1720,7 @@ _git_status ()
>                 return
>                 ;;
>         esac
> -       __git_complete_index_file
> +       __git_complete_index_file "--with-tree=HEAD --cached --deleted"

Might as well go all the way with  "--cached --deleted --unmerged
--others" no?  What is the point of --with-tree=HEAD?

Thanks.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] completion: add completer for status
  2013-06-28 13:20       ` Ramkumar Ramachandra
@ 2013-06-28 14:03         ` Ramkumar Ramachandra
  2013-06-30 11:00           ` SZEDER Gábor
  2013-06-28 14:04         ` SZEDER Gábor
  1 sibling, 1 reply; 9+ messages in thread
From: Ramkumar Ramachandra @ 2013-06-28 14:03 UTC (permalink / raw)
  To: SZEDER Gábor; +Cc: Git List, Junio C Hamano

Ramkumar Ramachandra wrote:
>> +       __git_complete_index_file "--with-tree=HEAD --cached --deleted"
>
> Might as well go all the way with  "--cached --deleted --unmerged
> --others" no?  What is the point of --with-tree=HEAD?

Ugh, --deleted doesn't work as advertised (terrible documentation).
The minimally correct combination we need seems to be
"--with-tree=HEAD --cached --others".

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] completion: add completer for status
  2013-06-28 13:20       ` Ramkumar Ramachandra
  2013-06-28 14:03         ` Ramkumar Ramachandra
@ 2013-06-28 14:04         ` SZEDER Gábor
  1 sibling, 0 replies; 9+ messages in thread
From: SZEDER Gábor @ 2013-06-28 14:04 UTC (permalink / raw)
  To: Ramkumar Ramachandra; +Cc: Git List, Junio C Hamano

On Fri, Jun 28, 2013 at 06:50:02PM +0530, Ramkumar Ramachandra wrote:
> SZEDER Gábor wrote:
> > diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> > index 912fb988..b68024c6 100644
> > --- a/contrib/completion/git-completion.bash
> > +++ b/contrib/completion/git-completion.bash
> > @@ -1697,6 +1697,8 @@ _git_stage ()
> >
> >  _git_status ()
> >  {
> > +       __git_has_doubledash && return
> > +
> 
> This line makes absolutely no sense to me.

That was my quick attempt to provide a way to complete untracked
files, but M-/ or '--others' will do as well.

> When the case statement
> fails to match anything (which it will, when a double-dash is
> present), we'll use the __git_complete_index_file which is superior to

And slower, too.

> returning and falling back to the dumb zsh file listing, no?  As a
> result, without that line,
> 
>   $ git status -- foo<TAB>
> 
> will complete fine when foo* isn't necessarily a file in the
> filesystem, but something that our ls-files returns, no?

If you want fancy completion replies, then you won't type the
doubledash.

> >         case "$cur" in
> >         --untracked-files=*)
> >                 __gitcomp "no normal all" "" "${cur##--untracked-files=}"
> > @@ -1718,7 +1720,7 @@ _git_status ()
> >                 return
> >                 ;;
> >         esac
> > -       __git_complete_index_file
> > +       __git_complete_index_file "--with-tree=HEAD --cached --deleted"
> 
> Might as well go all the way with  "--cached --deleted --unmerged
> --others" no?

'--unmerged' is definitely not good, it implies '--stage', which
changes the output format.

> What is the point of --with-tree=HEAD?

To list files that are deleted from the index:

$ rm version.h
$ git rm version.c
rm 'version.c'
$ git ls-files --deleted
version.h
$ git ls-files --deleted --with-tree=HEAD
version.c
version.h


Gábor

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] completion: add completer for status
  2013-06-28 14:03         ` Ramkumar Ramachandra
@ 2013-06-30 11:00           ` SZEDER Gábor
  0 siblings, 0 replies; 9+ messages in thread
From: SZEDER Gábor @ 2013-06-30 11:00 UTC (permalink / raw)
  To: Ramkumar Ramachandra; +Cc: Git List, Junio C Hamano

On Fri, Jun 28, 2013 at 07:33:21PM +0530, Ramkumar Ramachandra wrote:
> Ramkumar Ramachandra wrote:
> >> +       __git_complete_index_file "--with-tree=HEAD --cached --deleted"
> >
> > Might as well go all the way with  "--cached --deleted --unmerged
> > --others" no?  What is the point of --with-tree=HEAD?
> 
> Ugh, --deleted doesn't work as advertised (terrible documentation).

Why not?  In my experiments it worked well, as you can see in my
previous emails.  What behavior did you observe which differs from the
advertised?

> The minimally correct combination we need seems to be
> "--with-tree=HEAD --cached --others".

Yeah, once we use '--with-tree=HEAD' we don't need '--deleted'
anymore.


Gábor

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-06-30 11:01 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-24 17:22 [PATCH] completion: add completer for status Ramkumar Ramachandra
2013-06-24 17:28 ` Ramkumar Ramachandra
2013-06-28 10:29 ` SZEDER Gábor
2013-06-28 10:56   ` SZEDER Gábor
2013-06-28 11:26     ` SZEDER Gábor
2013-06-28 13:20       ` Ramkumar Ramachandra
2013-06-28 14:03         ` Ramkumar Ramachandra
2013-06-30 11:00           ` SZEDER Gábor
2013-06-28 14:04         ` SZEDER Gábor

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.