git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [StGit PATCH] Added basic bash completion script for StGit.
@ 2009-01-19 22:57 ted
  2009-01-19 23:15 ` Ted Pavlic
  0 siblings, 1 reply; 6+ messages in thread
From: ted @ 2009-01-19 22:57 UTC (permalink / raw)
  To: catalin.marinas; +Cc: git, Ted Pavlic

From: Ted Pavlic <ted@tedpavlic.com>

Signed-off-by: Ted Pavlic <ted@tedpavlic.com>
---
 contrib/completion/stg-completion.bash |  106 ++++++++++++++++++++++++++++++++
 1 files changed, 106 insertions(+), 0 deletions(-)
 create mode 100755 contrib/completion/stg-completion.bash

diff --git a/contrib/completion/stg-completion.bash b/contrib/completion/stg-completion.bash
new file mode 100755
index 0000000..13cc792
--- /dev/null
+++ b/contrib/completion/stg-completion.bash
@@ -0,0 +1,106 @@
+#!bash
+#
+# bash completion support for Stacked Git (StGit).
+#
+# Copyright (c) 2009 by Theodore P. Pavlic <ted@tedpavlic.com>
+# Distributed under the GNU General Public License, version 2.0.
+#
+# Design is highly influenced by completion scripts for Mercurial and
+# git.
+#
+# To use these routines:
+#
+#    1) Copy this file to somewhere (e.g. ~/.stg-completion.sh).
+#    2) Added the following line to your .bashrc or .bash_profile:
+#        source ~/.stg-completion.sh
+#
+# To submit patches:
+#
+#    *) Read Documentation/SubmittingPatches
+#    *) Send all patches to the Git mailing list
+#
+#           git@vger.kernel.org
+#
+#       and CC the message to the StGit maintainer
+#
+#           catalin.marinas@gmail.com
+#
+#       Prefix the subject with something like "[StGit PATCH]",
+#       "[StGit PATCH i/n]", "[StGit PATCH RFC]", or similar. Patches
+#       should be "Signed-off-by:" you as described in
+#       Documentation/SubmittingPatches.
+#
+#       It is recommended that editors submit patches using utilities
+#       like
+#
+#           stg mail
+#           git send-email
+#           git format-patch
+#
+#       In the latter case, make sure e-amils submitted to the list do
+#       not have "format=flowed" and do not "word wrap" your patch.
+#
+
+# This 'extglob' bash option allows for
+#       if [[ $param == @(-h|--help) ]]
+# type statements. That is, the pattern is true if $param matches -h OR
+# --help
+shopt -s extglob
+
+__stg_commands()
+{
+    local commands
+    commands="$("$stg" help|grep '^ '|cut -f3 -d' ' 2>/dev/null)" || commands=""
+    COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$commands' -- "$cur"))
+}
+
+__stg()
+{
+    local cur prev cmd
+    local stg="$1"
+
+    COMPREPLY=()
+    cur="$2"
+    prev="$3"
+
+    if [ $COMP_CWORD -gt 1 ]; then
+        # Try to complete the argument to an already complete stg command
+        # (e.g., "stg command partial<tab>")
+        cmd=${COMP_WORDS[${COMP_CWORD}-1]}
+        __stg_specific_command
+    else
+        # Try to complete an incomplete stg command (possibly blank)
+        # (e.g., "stg partial<tab>")
+        __stg_commands
+    fi
+
+}
+
+# Handle "stg command <tab>" completion
+__stg_specific_command()
+{
+    # Here, try to find (possibly user-defined) functions that match the
+    # command
+    if [ "$(type -t "__stg_cmd_$cmd")" = function ]; then
+        "__stg_cmd_$cmd"
+        return 0
+    fi
+
+    # Special handling of particular stg commands can be placed here
+    case "$cmd" in
+        help)
+            # Complete help with all possible help commands
+            __stg_commands
+            ;;
+        *)
+            # Bail out to normal bash completion
+            return 1
+            ;;
+   esac
+
+   return 0
+}
+
+# Use __stg for stg completion and bail out to normal bash completion
+complete -o bashdefault -o default -F __stg stg 2>/dev/null \
+    || complete -o default -F __stg stg
-- 
1.6.1.87.g15624

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

* Re: [StGit PATCH] Added basic bash completion script for StGit.
  2009-01-19 22:57 [StGit PATCH] Added basic bash completion script for StGit ted
@ 2009-01-19 23:15 ` Ted Pavlic
  2009-01-19 23:35   ` Ted Pavlic
  0 siblings, 1 reply; 6+ messages in thread
From: Ted Pavlic @ 2009-01-19 23:15 UTC (permalink / raw)
  To: Ted Pavlic; +Cc: catalin.marinas, git

> +# Use __stg for stg completion and bail out to normal bash completion
> +complete -o bashdefault -o default -F __stg stg 2>/dev/null \
> +    || complete -o default -F __stg stg

Somehow I didn't see the existing

	stgit-completion.bash

in stgit.git. I was looking in stgit.git/contrib, which is where Git 
(and Mercurial) puts its completion script.

So it looks like there's no need for this patch.

Thanks --
Ted

-- 
Ted Pavlic <ted@tedpavlic.com>

   Please visit my ALS association page:
         http://web.alsa.org/goto/tedpavlic
   My family appreciates your support in the fight to defeat ALS.

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

* Re: [StGit PATCH] Added basic bash completion script for StGit.
  2009-01-19 23:15 ` Ted Pavlic
@ 2009-01-19 23:35   ` Ted Pavlic
  2009-01-22 16:03     ` Karl Hasselström
  0 siblings, 1 reply; 6+ messages in thread
From: Ted Pavlic @ 2009-01-19 23:35 UTC (permalink / raw)
  To: Ted Pavlic; +Cc: catalin.marinas, git

>> +# Use __stg for stg completion and bail out to normal bash completion
>> +complete -o bashdefault -o default -F __stg stg 2>/dev/null \
>> +    || complete -o default -F __stg stg
>
> Somehow I didn't see the existing
>
> 	stgit-completion.bash

I didn't see it because it is generated in the build process. :(

Sorry for the bother --
Ted

-- 
Ted Pavlic <ted@tedpavlic.com>

   Please visit my ALS association page:
         http://web.alsa.org/goto/tedpavlic
   My family appreciates your support in the fight to defeat ALS.

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

* Re: [StGit PATCH] Added basic bash completion script for StGit.
  2009-01-19 23:35   ` Ted Pavlic
@ 2009-01-22 16:03     ` Karl Hasselström
  2009-01-22 16:09       ` Ted Pavlic
  0 siblings, 1 reply; 6+ messages in thread
From: Karl Hasselström @ 2009-01-22 16:03 UTC (permalink / raw)
  To: Ted Pavlic; +Cc: catalin.marinas, git

On 2009-01-19 18:35:39 -0500, Ted Pavlic wrote:

> I didn't see it because it is generated in the build process. :(

Yeah, sorry about that. I made it that way so it would be kept
up-to-date automatically (which works quite well, by the way).

-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle

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

* Re: [StGit PATCH] Added basic bash completion script for StGit.
  2009-01-22 16:03     ` Karl Hasselström
@ 2009-01-22 16:09       ` Ted Pavlic
  2009-01-22 16:18         ` Karl Hasselström
  0 siblings, 1 reply; 6+ messages in thread
From: Ted Pavlic @ 2009-01-22 16:09 UTC (permalink / raw)
  To: Karl Hasselström; +Cc: catalin.marinas, git

>> I didn't see it because it is generated in the build process. :(
>
> Yeah, sorry about that. I made it that way so it would be kept
> up-to-date automatically (which works quite well, by the way).

The only downside is that it's a little harder to keep track of when the 
completion script changes (e.g., when you have made your own local 
changes). However, the method you use provides very *fast* completion 
(as opposed to git and hg completion, which generate their keywords on 
the fly and thus run relatively slowly).


HOWEVER, please see the threads (which modify the Python that generates 
the script):

	[StGit PATCH 1/2] Modify bash completion to support help, version, and 
copyright.

	[StGit PATCH 2/2] Make bash completion fail to bashdefault before 
default completion.

The former thread could be implemented by making help, version, and 
copyright modules like the rest of the commands, but I think this method 
is fine (and it makes stg help <tab> show fewer entries).

	Thanks --
	Ted


-- 
Ted Pavlic <ted@tedpavlic.com>

   Please visit my ALS association page:
         http://web.alsa.org/goto/tedpavlic
   My family appreciates your support in the fight to defeat ALS.

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

* Re: [StGit PATCH] Added basic bash completion script for StGit.
  2009-01-22 16:09       ` Ted Pavlic
@ 2009-01-22 16:18         ` Karl Hasselström
  0 siblings, 0 replies; 6+ messages in thread
From: Karl Hasselström @ 2009-01-22 16:18 UTC (permalink / raw)
  To: Ted Pavlic; +Cc: catalin.marinas, git

On 2009-01-22 11:09:03 -0500, Ted Pavlic wrote:

> The only downside is that it's a little harder to keep track of when
> the completion script changes (e.g., when you have made your own
> local changes).

It's a generated file -- you're not supposed to edit it! Wouldn't it
be a better idea to edit the program that generates it instead?

> However, the method you use provides very *fast* completion (as
> opposed to git and hg completion, which generate their keywords on
> the fly and thus run relatively slowly).

Yes, I was always irritated by how slow the StGit completion was
compared to git's. Python sucks in this respect.

> HOWEVER, please see the threads (which modify the Python that
> generates the script):

Yes, I'll take a look.

-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle

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

end of thread, other threads:[~2009-01-22 16:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-19 22:57 [StGit PATCH] Added basic bash completion script for StGit ted
2009-01-19 23:15 ` Ted Pavlic
2009-01-19 23:35   ` Ted Pavlic
2009-01-22 16:03     ` Karl Hasselström
2009-01-22 16:09       ` Ted Pavlic
2009-01-22 16:18         ` Karl Hasselström

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