threads / patch / 17264

patch, 2 partsModify bash completion to support help, version, and copyright.

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

## tl;dr

7 messages between Jan 20, 2009 and Jan 23, 2009. Diffs are folded; open one to read it.

replies: 6people: 2as markdown or json

ted@tedpavlic.com· Jan 20, 2009, 00:46 UTC · lore
From: Ted Pavlic <ted@tedpavlic.com>

"stg <tab>" lists all commands, including "help", "version", and "copyright".

"stg he<tab>" completes "stg help " "stg ver<tab>" completes "stg version " "stg copy<tab>" completes "stg copyright "

"stg help <tab>" lists all commands /other than/ help, version, and copyright.

"stg version <tab>" goes directly to shell completion. "stg copyright <tab>" goes directly to shell completion.

Signed-off-by: Ted Pavlic <ted@tedpavlic.com>
---
 stgit/completion.py |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
Show changes to stgit/completion.py +7 −1
diff --git a/stgit/completion.py b/stgit/completion.py
index affc8c6..b3fd282 100644
--- a/stgit/completion.py
+++ b/stgit/completion.py
@@ -111,13 +111,19 @@ def main_switch(commands):
         ('# Complete name of subcommand if the user has not finished'
          ' typing it yet.'),
         'if test $c -eq $COMP_CWORD -a -z "$command"; then', [
-            ('COMPREPLY=($(compgen -W "$_stg_commands" --'
+            ('COMPREPLY=($(compgen -W "help version copyright $_stg_commands" --'
              ' "${COMP_WORDS[COMP_CWORD]}"))'),
             'return'],
         'fi',
         '',
         '# Complete arguments to subcommands.',
         'case "$command" in', [
+            'help) ', [
+            ('COMPREPLY=($(compgen -W "$_stg_commands" --'
+             ' "${COMP_WORDS[COMP_CWORD]}"))'),
+            'return ;;'],
+            'version) return ;;',
+            'copyright) return ;;'], [
             '%s) _stg_%s ;;' % (cmd, cmd)
             for cmd in sorted(commands.iterkeys())],
         'esac')
-- 
1.6.1.87.g15624
ted@tedpavlic.com· Jan 20, 2009, 00:46 UTC · re: ted@tedpavlic.com · lore

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

From: Ted Pavlic <ted@tedpavlic.com>
If "-o bashdefault" isn't possible, use old "-o default" only.

(this patch inspired by similar mechanism in Mercurial bash completion script)

Signed-off-by: Ted Pavlic <ted@tedpavlic.com>
---
 stgit/completion.py |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
Show changes to stgit/completion.py +2 −1
diff --git a/stgit/completion.py b/stgit/completion.py
index b3fd282..56e81c2 100644
--- a/stgit/completion.py
+++ b/stgit/completion.py
@@ -129,7 +129,8 @@ def main_switch(commands):
         'esac')
 
 def install():
-    return ['complete -o default -F _stg stg']
+    return ['complete -o bashdefault -o default -F _stg stg 2>/dev/null \\', [
+            'complete -o default -F _stg stg' ] ]
 
 def write_completion(f):
     commands = stgit.commands.get_commands(allow_cached = False)
-- 
1.6.1.87.g15624
Ted Pavlic· Jan 22, 2009, 16:38 UTC · re: ted@tedpavlic.com · lore

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

>   def install():
> -    return ['complete -o default -F _stg stg']
> +    return ['complete -o bashdefault -o default -F _stg stg 2>/dev/null \\', [
> +            'complete -o default -F _stg stg' ] ]
Oops -- that second "complete" should have two pipes in front of it...
-- 
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.
Ted Pavlic· Jan 22, 2009, 16:44 UTC · re: Ted Pavlic · lore

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

If "-o bashdefault" isn't possible, use old "-o default" only.

(this patch inspired by similar mechanism in Mercurial bash completion script)

Signed-off-by: Ted Pavlic <ted@tedpavlic.com>
---

This patch corrects a bug in the previous one of the same name. In particular, the second "complete" lacked the "||" in front of it needed for proper operation. The first complete command should fail over to the second if "bashdefault" isn't available.

 stgit/completion.py |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
Show changes to stgit/completion.py +2 −1
diff --git a/stgit/completion.py b/stgit/completion.py
index b3fd282..38f0670 100644
--- a/stgit/completion.py
+++ b/stgit/completion.py
@@ -129,7 +129,8 @@ def main_switch(commands):
         'esac')
 
 def install():
-    return ['complete -o default -F _stg stg']
+    return ['complete -o bashdefault -o default -F _stg stg 2>/dev/null \\', [
+            '|| complete -o default -F _stg stg' ] ]
 
 def write_completion(f):
     commands = stgit.commands.get_commands(allow_cached = False)
-- 
1.6.1.213.g28da8
Karl Hasselström· Jan 22, 2009, 23:29 UTC · re: ted@tedpavlic.com · lore

kha/{stable,safe,experimental} updated

Ted, Both of your patches look good, and work when I try them. (Excellent commit messages, by the way.) I've applied them and pushed them out.

Catalin, I have stuff for you in both kha/stable and kha/safe.
                                 -+-
The following changes since commit 7cb253c05b509510177a1df4d5813861641968f6:
  Karl Hasselström (1):
        Fix typo
are available in the git repository at:
  git://repo.or.cz/stgit/kha.git stable
Karl Hasselström (1):
      Return None instead of crashing on undefined integer config items
Pete Wyckoff (1):
      stgit.namelength is an integer
 stgit/config.py |    4 +++-
 stgit/utils.py  |    2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)
                                 -+-
The following changes since commit d3b31eeac6c6fba9352188755164f556faf56e59:
  Catalin Marinas (1):
        Fix the patch argument parsing for the "show" command
are available in the git repository at:
  git://repo.or.cz/stgit/kha.git safe
Gustav Hållberg (7):
      stgit.el: Consistently use symbols rather than strings for patch names
      stgit.el: Make single file diff buffer read-only
      stgit.el: Include stat summary in patch diff
      stgit.el: Add message when there are no patches in the series
      stgit.el: Indicate empty patches
      stgit.el: Minor beautification
      stgit.el: Add optional count argument to stgit-commit
Karl Hasselström (2):
      Return None instead of crashing on undefined integer config items
      Merge branch 'stable'
Pete Wyckoff (1):
      stgit.namelength is an integer
Ted Pavlic (2):
      Modify bash completion to support help, version, and copyright.
      Make bash completion fail to bashdefault before default completion.
 contrib/stgit.el    |  245 ++++++++++++++++++++++++++++-----------------------
 stgit/completion.py |   11 ++-
 stgit/config.py     |    4 +-
 stgit/utils.py      |    2 +-
 4 files changed, 146 insertions(+), 116 deletions(-)
                                 -+-
The following changes since commit e80d43bd9c8baf2bc9913c6c153914403f210872:
  Ted Pavlic (1):
        Make bash completion fail to bashdefault before default completion.
are available in the git repository at:
  git://repo.or.cz/stgit/kha.git experimental
Gustav Hållberg (1):
      stgit.el: (EXPERIMENTAL) Show files modified in work tree
Karl Hasselström (2):
      Read several objects at once with git cat-file --batch
      Diff several trees at once with git diff-tree --stdin
 INSTALL          |    5 +-
 contrib/stgit.el |  272 ++++++++++++++++++++++++++++++++++--------------------
 stgit/lib/git.py |   79 +++++++++++++++-
 stgit/run.py     |   19 ++++
 4 files changed, 266 insertions(+), 109 deletions(-)
-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle
Ted Pavlic· Jan 23, 2009, 00:26 UTC · re: Karl Hasselström · lore

[kha/safe PATCH] completion bugfix: Place double pipes in front of alternate command.

Signed-off-by: Ted Pavlic <ted@tedpavlic.com>
---
This is a patch against 
    git://repo.or.cz/stgit/kha.git stable

Unfortunately, the previous "[StGit PATCH 2/2]" had a small bug in it. A bugfix was posted, but it didn't get picked up in kha/safe. This commit should be applied against kha/safe to fix the problem.

Alternatively, the patch provided in
    <1232642662-12851-1-git-send-email-ted@tedpavlic.com>
is the proper patch to stgit/master.
Sorry for the extra bother.
 stgit/completion.py |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Show changes to stgit/completion.py +1 −1
diff --git a/stgit/completion.py b/stgit/completion.py
index 56e81c2..38f0670 100644
--- a/stgit/completion.py
+++ b/stgit/completion.py
@@ -130,7 +130,7 @@ def main_switch(commands):
 
 def install():
     return ['complete -o bashdefault -o default -F _stg stg 2>/dev/null \\', [
-            'complete -o default -F _stg stg' ] ]
+            '|| complete -o default -F _stg stg' ] ]
 
 def write_completion(f):
     commands = stgit.commands.get_commands(allow_cached = False)
-- 
1.6.1.213.g28da8
Karl Hasselström· Jan 23, 2009, 01:35 UTC · re: Ted Pavlic · lore

Re: [kha/safe PATCH] completion bugfix: Place double pipes in front of alternate command.

On 2009-01-22 19:26:12 -0500, Ted Pavlic wrote:
> -            'complete -o default -F _stg stg' ] ]
> +            '|| complete -o default -F _stg stg' ] ]
Thanks, I've edited the patch and pushed it out again.
-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle

← back to recent threads