git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
* [PATCH v2 1/2] completion: use "prev" variable instead of introducing "prevword"
@ 2020-09-25 21:11 Ákos Uzonyi
  2020-09-25 21:11 ` [PATCH v2 2/2] completion: complete refs after 'git restore -s' Ákos Uzonyi
  2020-09-25 22:53 ` [PATCH v2 1/2] completion: use "prev" variable instead of introducing "prevword" Jacob Keller
  0 siblings, 2 replies; 4+ messages in thread
From: Ákos Uzonyi @ 2020-09-25 21:11 UTC (permalink / raw)
  To: git
  Cc: Ákos Uzonyi, Nguyễn Thái Ngọc Duy,
	Junio C Hamano, Thomas Braun, Jacob Keller

In both _git_checkout and _git_switch a new "prevword" variable were
introduced, however the "prev" variable already contains the last word.

The "prevword" variable is replaced with "prev", and the case is moved
to the beginning of the function, like it's done in many other places
(e.g. _git_commit). Also the indentaion of the case is fixed.

Signed-off-by: Ákos Uzonyi <uzonyi.akos@gmail.com>
---
 contrib/completion/git-completion.bash | 66 +++++++++++++-------------
 1 file changed, 32 insertions(+), 34 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 8be4a0316e..3d02bd4de7 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1508,6 +1508,22 @@ _git_checkout ()
 {
 	__git_has_doubledash && return
 
+	local dwim_opt="$(__git_checkout_default_dwim_mode)"
+
+	case "$prev" in
+	-b|-B|--orphan)
+		# Complete local branches (and DWIM branch
+		# remote branch names) for an option argument
+		# specifying a new branch name. This is for
+		# convenience, assuming new branches are
+		# possibly based on pre-existing branch names.
+		__git_complete_refs $dwim_opt --mode="heads"
+		return
+		;;
+	*)
+		;;
+	esac
+
 	case "$cur" in
 	--conflict=*)
 		__gitcomp "diff3 merge" "" "${cur##--conflict=}"
@@ -1516,23 +1532,6 @@ _git_checkout ()
 		__gitcomp_builtin checkout
 		;;
 	*)
-		local dwim_opt="$(__git_checkout_default_dwim_mode)"
-		local prevword prevword="${words[cword-1]}"
-
-		case "$prevword" in
-			-b|-B|--orphan)
-				# Complete local branches (and DWIM branch
-				# remote branch names) for an option argument
-				# specifying a new branch name. This is for
-				# convenience, assuming new branches are
-				# possibly based on pre-existing branch names.
-				__git_complete_refs $dwim_opt --mode="heads"
-				return
-				;;
-			*)
-				;;
-		esac
-
 		# At this point, we've already handled special completion for
 		# the arguments to -b/-B, and --orphan. There are 3 main
 		# things left we can possibly complete:
@@ -2392,6 +2391,22 @@ _git_status ()
 
 _git_switch ()
 {
+	local dwim_opt="$(__git_checkout_default_dwim_mode)"
+
+	case "$prev" in
+	-c|-C|--orphan)
+		# Complete local branches (and DWIM branch
+		# remote branch names) for an option argument
+		# specifying a new branch name. This is for
+		# convenience, assuming new branches are
+		# possibly based on pre-existing branch names.
+		__git_complete_refs $dwim_opt --mode="heads"
+		return
+		;;
+	*)
+		;;
+	esac
+
 	case "$cur" in
 	--conflict=*)
 		__gitcomp "diff3 merge" "" "${cur##--conflict=}"
@@ -2400,23 +2415,6 @@ _git_switch ()
 		__gitcomp_builtin switch
 		;;
 	*)
-		local dwim_opt="$(__git_checkout_default_dwim_mode)"
-		local prevword prevword="${words[cword-1]}"
-
-		case "$prevword" in
-			-c|-C|--orphan)
-				# Complete local branches (and DWIM branch
-				# remote branch names) for an option argument
-				# specifying a new branch name. This is for
-				# convenience, assuming new branches are
-				# possibly based on pre-existing branch names.
-				__git_complete_refs $dwim_opt --mode="heads"
-				return
-				;;
-			*)
-				;;
-		esac
-
 		# Unlike in git checkout, git switch --orphan does not take
 		# a start point. Thus we really have nothing to complete after
 		# the branch name.
-- 
2.28.0


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

* [PATCH v2 2/2] completion: complete refs after 'git restore -s'
  2020-09-25 21:11 [PATCH v2 1/2] completion: use "prev" variable instead of introducing "prevword" Ákos Uzonyi
@ 2020-09-25 21:11 ` Ákos Uzonyi
  2020-09-25 22:53 ` [PATCH v2 1/2] completion: use "prev" variable instead of introducing "prevword" Jacob Keller
  1 sibling, 0 replies; 4+ messages in thread
From: Ákos Uzonyi @ 2020-09-25 21:11 UTC (permalink / raw)
  To: git
  Cc: Ákos Uzonyi, Nguyễn Thái Ngọc Duy, Junio C Hamano

Currently only the long version (--source=) supports completion.

Add completion support to the short (-s) option too.

Signed-off-by: Ákos Uzonyi <uzonyi.akos@gmail.com>
---
 contrib/completion/git-completion.bash | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 3d02bd4de7..0a96ad87e7 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2841,6 +2841,13 @@ _git_reset ()
 
 _git_restore ()
 {
+	case "$prev" in
+	-s)
+		__git_complete_refs
+		return
+		;;
+	esac
+
 	case "$cur" in
 	--conflict=*)
 		__gitcomp "diff3 merge" "" "${cur##--conflict=}"
-- 
2.28.0


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

* Re: [PATCH v2 1/2] completion: use "prev" variable instead of introducing "prevword"
  2020-09-25 21:11 [PATCH v2 1/2] completion: use "prev" variable instead of introducing "prevword" Ákos Uzonyi
  2020-09-25 21:11 ` [PATCH v2 2/2] completion: complete refs after 'git restore -s' Ákos Uzonyi
@ 2020-09-25 22:53 ` Jacob Keller
  2020-09-26 22:31   ` Junio C Hamano
  1 sibling, 1 reply; 4+ messages in thread
From: Jacob Keller @ 2020-09-25 22:53 UTC (permalink / raw)
  To: Ákos Uzonyi
  Cc: Git mailing list, Nguyễn Thái Ngọc Duy,
	Junio C Hamano, Thomas Braun

On Fri, Sep 25, 2020 at 3:00 PM Ákos Uzonyi <uzonyi.akos@gmail.com> wrote:
>
> In both _git_checkout and _git_switch a new "prevword" variable were
> introduced, however the "prev" variable already contains the last word.
>
> The "prevword" variable is replaced with "prev", and the case is moved
> to the beginning of the function, like it's done in many other places
> (e.g. _git_commit). Also the indentaion of the case is fixed.
>

Ahhh... didn't realize $prev existed.

> Signed-off-by: Ákos Uzonyi <uzonyi.akos@gmail.com>
> ---
>  contrib/completion/git-completion.bash | 66 +++++++++++++-------------
>  1 file changed, 32 insertions(+), 34 deletions(-)
>
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 8be4a0316e..3d02bd4de7 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -1508,6 +1508,22 @@ _git_checkout ()
>  {
>         __git_has_doubledash && return
>
> +       local dwim_opt="$(__git_checkout_default_dwim_mode)"
> +
> +       case "$prev" in
> +       -b|-B|--orphan)
> +               # Complete local branches (and DWIM branch
> +               # remote branch names) for an option argument
> +               # specifying a new branch name. This is for
> +               # convenience, assuming new branches are
> +               # possibly based on pre-existing branch names.
> +               __git_complete_refs $dwim_opt --mode="heads"
> +               return
> +               ;;
> +       *)
> +               ;;
> +       esac
> +
>         case "$cur" in
>         --conflict=*)
>                 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
> @@ -1516,23 +1532,6 @@ _git_checkout ()
>                 __gitcomp_builtin checkout
>                 ;;
>         *)
> -               local dwim_opt="$(__git_checkout_default_dwim_mode)"
> -               local prevword prevword="${words[cword-1]}"
> -
> -               case "$prevword" in
> -                       -b|-B|--orphan)
> -                               # Complete local branches (and DWIM branch
> -                               # remote branch names) for an option argument
> -                               # specifying a new branch name. This is for
> -                               # convenience, assuming new branches are
> -                               # possibly based on pre-existing branch names.
> -                               __git_complete_refs $dwim_opt --mode="heads"
> -                               return
> -                               ;;
> -                       *)
> -                               ;;
> -               esac
> -
>                 # At this point, we've already handled special completion for
>                 # the arguments to -b/-B, and --orphan. There are 3 main
>                 # things left we can possibly complete:
> @@ -2392,6 +2391,22 @@ _git_status ()
>
>  _git_switch ()
>  {
> +       local dwim_opt="$(__git_checkout_default_dwim_mode)"
> +
> +       case "$prev" in
> +       -c|-C|--orphan)
> +               # Complete local branches (and DWIM branch
> +               # remote branch names) for an option argument
> +               # specifying a new branch name. This is for
> +               # convenience, assuming new branches are
> +               # possibly based on pre-existing branch names.
> +               __git_complete_refs $dwim_opt --mode="heads"
> +               return
> +               ;;
> +       *)
> +               ;;
> +       esac
> +
>         case "$cur" in
>         --conflict=*)
>                 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
> @@ -2400,23 +2415,6 @@ _git_switch ()
>                 __gitcomp_builtin switch
>                 ;;
>         *)
> -               local dwim_opt="$(__git_checkout_default_dwim_mode)"
> -               local prevword prevword="${words[cword-1]}"
> -
> -               case "$prevword" in
> -                       -c|-C|--orphan)
> -                               # Complete local branches (and DWIM branch
> -                               # remote branch names) for an option argument
> -                               # specifying a new branch name. This is for
> -                               # convenience, assuming new branches are
> -                               # possibly based on pre-existing branch names.
> -                               __git_complete_refs $dwim_opt --mode="heads"
> -                               return
> -                               ;;
> -                       *)
> -                               ;;
> -               esac
> -
>                 # Unlike in git checkout, git switch --orphan does not take
>                 # a start point. Thus we really have nothing to complete after
>                 # the branch name.
> --
> 2.28.0
>

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

* Re: [PATCH v2 1/2] completion: use "prev" variable instead of introducing "prevword"
  2020-09-25 22:53 ` [PATCH v2 1/2] completion: use "prev" variable instead of introducing "prevword" Jacob Keller
@ 2020-09-26 22:31   ` Junio C Hamano
  0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2020-09-26 22:31 UTC (permalink / raw)
  To: Jacob Keller
  Cc: Ákos Uzonyi, Git mailing list,
	Nguyễn Thái Ngọc Duy, Thomas Braun

Jacob Keller <jacob.keller@gmail.com> writes:

> On Fri, Sep 25, 2020 at 3:00 PM Ákos Uzonyi <uzonyi.akos@gmail.com> wrote:
>>
>> In both _git_checkout and _git_switch a new "prevword" variable were
>> introduced, however the "prev" variable already contains the last word.
>>
>> The "prevword" variable is replaced with "prev", and the case is moved
>> to the beginning of the function, like it's done in many other places
>> (e.g. _git_commit). Also the indentaion of the case is fixed.
>>
>
> Ahhh... didn't realize $prev existed.

Yup, makes a lot of sense.

Thanks, Ákos.  Will queue.

>
>> Signed-off-by: Ákos Uzonyi <uzonyi.akos@gmail.com>
>> ---
>>  contrib/completion/git-completion.bash | 66 +++++++++++++-------------
>>  1 file changed, 32 insertions(+), 34 deletions(-)
>>
>> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
>> index 8be4a0316e..3d02bd4de7 100644
>> --- a/contrib/completion/git-completion.bash
>> +++ b/contrib/completion/git-completion.bash
>> @@ -1508,6 +1508,22 @@ _git_checkout ()
>>  {
>>         __git_has_doubledash && return
>>
>> +       local dwim_opt="$(__git_checkout_default_dwim_mode)"
>> +
>> +       case "$prev" in
>> +       -b|-B|--orphan)
>> +               # Complete local branches (and DWIM branch
>> +               # remote branch names) for an option argument
>> +               # specifying a new branch name. This is for
>> +               # convenience, assuming new branches are
>> +               # possibly based on pre-existing branch names.
>> +               __git_complete_refs $dwim_opt --mode="heads"
>> +               return
>> +               ;;
>> +       *)
>> +               ;;
>> +       esac
>> +
>>         case "$cur" in
>>         --conflict=*)
>>                 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
>> @@ -1516,23 +1532,6 @@ _git_checkout ()
>>                 __gitcomp_builtin checkout
>>                 ;;
>>         *)
>> -               local dwim_opt="$(__git_checkout_default_dwim_mode)"
>> -               local prevword prevword="${words[cword-1]}"
>> -
>> -               case "$prevword" in
>> -                       -b|-B|--orphan)
>> -                               # Complete local branches (and DWIM branch
>> -                               # remote branch names) for an option argument
>> -                               # specifying a new branch name. This is for
>> -                               # convenience, assuming new branches are
>> -                               # possibly based on pre-existing branch names.
>> -                               __git_complete_refs $dwim_opt --mode="heads"
>> -                               return
>> -                               ;;
>> -                       *)
>> -                               ;;
>> -               esac
>> -
>>                 # At this point, we've already handled special completion for
>>                 # the arguments to -b/-B, and --orphan. There are 3 main
>>                 # things left we can possibly complete:
>> @@ -2392,6 +2391,22 @@ _git_status ()
>>
>>  _git_switch ()
>>  {
>> +       local dwim_opt="$(__git_checkout_default_dwim_mode)"
>> +
>> +       case "$prev" in
>> +       -c|-C|--orphan)
>> +               # Complete local branches (and DWIM branch
>> +               # remote branch names) for an option argument
>> +               # specifying a new branch name. This is for
>> +               # convenience, assuming new branches are
>> +               # possibly based on pre-existing branch names.
>> +               __git_complete_refs $dwim_opt --mode="heads"
>> +               return
>> +               ;;
>> +       *)
>> +               ;;
>> +       esac
>> +
>>         case "$cur" in
>>         --conflict=*)
>>                 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
>> @@ -2400,23 +2415,6 @@ _git_switch ()
>>                 __gitcomp_builtin switch
>>                 ;;
>>         *)
>> -               local dwim_opt="$(__git_checkout_default_dwim_mode)"
>> -               local prevword prevword="${words[cword-1]}"
>> -
>> -               case "$prevword" in
>> -                       -c|-C|--orphan)
>> -                               # Complete local branches (and DWIM branch
>> -                               # remote branch names) for an option argument
>> -                               # specifying a new branch name. This is for
>> -                               # convenience, assuming new branches are
>> -                               # possibly based on pre-existing branch names.
>> -                               __git_complete_refs $dwim_opt --mode="heads"
>> -                               return
>> -                               ;;
>> -                       *)
>> -                               ;;
>> -               esac
>> -
>>                 # Unlike in git checkout, git switch --orphan does not take
>>                 # a start point. Thus we really have nothing to complete after
>>                 # the branch name.
>> --
>> 2.28.0
>>

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

end of thread, other threads:[~2020-09-26 22:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-25 21:11 [PATCH v2 1/2] completion: use "prev" variable instead of introducing "prevword" Ákos Uzonyi
2020-09-25 21:11 ` [PATCH v2 2/2] completion: complete refs after 'git restore -s' Ákos Uzonyi
2020-09-25 22:53 ` [PATCH v2 1/2] completion: use "prev" variable instead of introducing "prevword" Jacob Keller
2020-09-26 22:31   ` Junio C Hamano

git@vger.kernel.org list mirror (unofficial, one of many)

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 git git/ https://public-inbox.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.io/gmane.comp.version-control.git
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git