zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: _quilt: fix push and pop completion
@ 2011-07-26 22:57 Luka Perkov
  2011-07-27  7:50 ` Frank Terbeck
  0 siblings, 1 reply; 5+ messages in thread
From: Luka Perkov @ 2011-07-26 22:57 UTC (permalink / raw)
  To: zsh-workers

Patch fixes 'bug' in _quilt completion script when there is not possible
to do push or pop. Also tabs are replaced with spaces because they were
not consistent.

Signed-off-by: Luka Perkov < lists ->-to->- lukaperkov.net >
---

diff --git a/Completion/Unix/Command/_quilt b/Completion/Unix/Command/_quilt
index a2fd799..d12a672 100644
--- a/Completion/Unix/Command/_quilt
+++ b/Completion/Unix/Command/_quilt
@@ -14,17 +14,23 @@ case "$state" in
 
   case "$words[1]" in
       (applied|delete|files|graph|header|next|previous|refresh|unapplied)
-      	_wanted -V 'patches' expl 'patch' compadd ${(f)"$(quilt series)"}
-	;;
+        _wanted -V 'patches' expl 'patch' compadd ${(f)"$(quilt series)"}
+        ;;
       (push)
-    	_wanted -V 'unapplied patches' expl 'patch' compadd ${(f)"$(quilt unapplied)"}
-    	;;
+        tmp=$(quilt unapplied 2>&1)
+        if [[ "$tmp[1,40]" != "File series fully applied, ends at patch" ]]; then
+          _wanted -V 'unapplied patches' expl 'patch' compadd ${(f)"$(quilt unapplied)"}
+        fi
+        ;;
       (pop)
-    	_wanted -V 'applied patches' expl 'patch' compadd ${(f)"$(quilt applied)"}
-    	;;
+        tmp=$(quilt applied 2>&1)
+        if [[ "$tmp" != "No patches applied" ]]; then
+          _wanted -V 'applied patches' expl 'patch' compadd ${(f)"$(quilt applied)"}
+        fi
+        ;;
       (*)
-    	_files
-    	;;
+        _files
+        ;;
   esac
   ;;
 esac


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

* Re: PATCH: _quilt: fix push and pop completion
  2011-07-26 22:57 PATCH: _quilt: fix push and pop completion Luka Perkov
@ 2011-07-27  7:50 ` Frank Terbeck
  2011-07-27 18:21   ` Luka Perkov
  0 siblings, 1 reply; 5+ messages in thread
From: Frank Terbeck @ 2011-07-27  7:50 UTC (permalink / raw)
  To: Luka Perkov; +Cc: zsh-workers

Luka Perkov wrote:
> Patch fixes 'bug' in _quilt completion script when there is not possible
> to do push or pop. Also tabs are replaced with spaces because they were
> not consistent.

This still doesn't quite work for me.

When I'm trying push or pop completion in a directory where there are no
quilt patches at all, the completion is still echoing back error
messages to me.

Also, your patch runs `quilt' twice, which is not needed.

How about checking for the return value of `quilt' after running the
{un,}applied sub-commands?

The following seems to work:


diff --git a/Completion/Unix/Command/_quilt b/Completion/Unix/Command/_quilt
index a2fd799..fd475ed 100644
--- a/Completion/Unix/Command/_quilt
+++ b/Completion/Unix/Command/_quilt
@@ -1,5 +1,8 @@
 #compdef quilt
 
+local -a tmp
+local rc
+
 _arguments \
   '--trace' \
   '--quiltrc:config file:_files' \
@@ -14,17 +17,29 @@ case "$state" in
 
   case "$words[1]" in
       (applied|delete|files|graph|header|next|previous|refresh|unapplied)
-      	_wanted -V 'patches' expl 'patch' compadd ${(f)"$(quilt series)"}
-	;;
+        _wanted -V 'patches' expl 'patch' compadd ${(f)"$(quilt series)"}
+        ;;
       (push)
-    	_wanted -V 'unapplied patches' expl 'patch' compadd ${(f)"$(quilt unapplied)"}
-    	;;
+        tmp=( ${(f)"$(quilt unapplied 2>&1)"} )
+        rc=$?
+        if (( rc == 0 )); then
+          _wanted -V 'unapplied patches' expl 'patch' compadd "${tmp[@]}"
+        else
+          _message "No unapplied patches"
+        fi
+        ;;
       (pop)
-    	_wanted -V 'applied patches' expl 'patch' compadd ${(f)"$(quilt applied)"}
-    	;;
+        tmp=( ${(f)"$(quilt applied 2>&1)"} )
+        rc=$?
+        if (( rc == 0 )); then
+          _wanted -V 'applied patches' expl 'patch' compadd "${tmp[@]}"
+        else
+          _message "No applied patches"
+        fi
+        ;;
       (*)
-    	_files
-    	;;
+        _files
+        ;;
   esac
   ;;
 esac


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

* Re: PATCH: _quilt: fix push and pop completion
  2011-07-27  7:50 ` Frank Terbeck
@ 2011-07-27 18:21   ` Luka Perkov
  2011-07-29 13:10     ` Frank Terbeck
  0 siblings, 1 reply; 5+ messages in thread
From: Luka Perkov @ 2011-07-27 18:21 UTC (permalink / raw)
  To: Frank Terbeck; +Cc: zsh-workers

On Wed, Jul 27, 2011 at 09:50:19AM +0200, Frank Terbeck wrote:
> Luka Perkov wrote:
> > Patch fixes 'bug' in _quilt completion script when there is not possible
> > to do push or pop. Also tabs are replaced with spaces because they were
> > not consistent.
> 
> This still doesn't quite work for me.
> 
> When I'm trying push or pop completion in a directory where there are no
> quilt patches at all, the completion is still echoing back error
> messages to me.
> 
> Also, your patch runs `quilt' twice, which is not needed.

Yes, I knew this and could not find way around it. I'm glad you did :)

> How about checking for the return value of `quilt' after running the
> {un,}applied sub-commands?

Great. I fixed it a bit more so when you run for example 'quilt pop' you
can only choose one patch; that is how it should work. That's the
'CURRENT == 2' stuff... 

I think this can be applied if that is ok with everyone.

diff --git a/Completion/Unix/Command/_quilt b/Completion/Unix/Command/_quilt
index a2fd799..0c51ba5 100644
--- a/Completion/Unix/Command/_quilt
+++ b/Completion/Unix/Command/_quilt
@@ -1,5 +1,8 @@
 #compdef quilt
 
+local -a tmp
+local rc
+
 _arguments \
   '--trace' \
   '--quiltrc:config file:_files' \
@@ -10,21 +13,37 @@ _arguments \
   '*::subcmd:->subcmd' && return 0
 
 case "$state" in
-    (subcmd)
+  (subcmd)
 
   case "$words[1]" in
       (applied|delete|files|graph|header|next|previous|refresh|unapplied)
-      	_wanted -V 'patches' expl 'patch' compadd ${(f)"$(quilt series)"}
-	;;
+        _wanted -V 'patches' expl 'patch' compadd ${(f)"$(quilt series)"}
+        ;;
       (push)
-    	_wanted -V 'unapplied patches' expl 'patch' compadd ${(f)"$(quilt unapplied)"}
-    	;;
+        if (( CURRENT == 2 )); then
+          tmp=( ${(f)"$(quilt unapplied 2>&1)"} )
+          rc=$?
+          if (( rc == 0 )); then
+            _wanted -V 'unapplied patches' expl 'patch' compadd "${tmp[@]}"
+          else
+            _message "No unapplied patches"
+          fi
+        fi
+        ;;
       (pop)
-    	_wanted -V 'applied patches' expl 'patch' compadd ${(f)"$(quilt applied)"}
-    	;;
+        if (( CURRENT == 2 )); then
+          tmp=( ${(f)"$(quilt applied 2>&1)"} )
+          rc=$?
+          if (( rc == 0 )); then
+            _wanted -V 'applied patches' expl 'patch' compadd "${tmp[@]}"
+          else
+            _message "No applied patches"
+          fi
+        fi
+        ;;
       (*)
-    	_files
-    	;;
+        _files
+        ;;
   esac
   ;;
 esac


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

* Re: PATCH: _quilt: fix push and pop completion
  2011-07-27 18:21   ` Luka Perkov
@ 2011-07-29 13:10     ` Frank Terbeck
  2011-07-29 22:15       ` Luka Perkov
  0 siblings, 1 reply; 5+ messages in thread
From: Frank Terbeck @ 2011-07-29 13:10 UTC (permalink / raw)
  To: Luka Perkov; +Cc: zsh-workers

Luka Perkov wrote:
[...]
> I think this can be applied if that is ok with everyone.

[x] done.


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

* Re: PATCH: _quilt: fix push and pop completion
  2011-07-29 13:10     ` Frank Terbeck
@ 2011-07-29 22:15       ` Luka Perkov
  0 siblings, 0 replies; 5+ messages in thread
From: Luka Perkov @ 2011-07-29 22:15 UTC (permalink / raw)
  To: Frank Terbeck; +Cc: zsh-workers

On Fri, Jul 29, 2011 at 03:10:58PM +0200, Frank Terbeck wrote:
> Luka Perkov wrote:
> [...]
> > I think this can be applied if that is ok with everyone.
> 
> [x] done.

Thank you,
Luka


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

end of thread, other threads:[~2011-07-29 22:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-26 22:57 PATCH: _quilt: fix push and pop completion Luka Perkov
2011-07-27  7:50 ` Frank Terbeck
2011-07-27 18:21   ` Luka Perkov
2011-07-29 13:10     ` Frank Terbeck
2011-07-29 22:15       ` Luka Perkov

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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).