changeset 7466:05010666fb19

Update zsh completion for new help format
author Brendan Cully <brendan@kublai.com>
date Wed, 03 Dec 2008 22:01:34 -0800
parents 3a829f29d1e2
children 0d1c5e638d07
files contrib/zsh_completion
diffstat 1 files changed, 48 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/zsh_completion	Wed Dec 03 01:28:33 2008 +0100
+++ b/contrib/zsh_completion	Wed Dec 03 22:01:34 2008 -0800
@@ -4,14 +4,13 @@
 # it into your zsh function path (/usr/share/zsh/site-functions for
 # instance)
 #
-# Copyright (C) 2005 Steve Borho
+# Copyright (C) 2005-6 Steve Borho
 # Copyright (C) 2006-8 Brendan Cully <brendan@kublai.com>
 #
 # This is free software; you can redistribute it and/or modify it under
 # the terms of the GNU General Public License as published by the Free
 # Software Foundation; either version 2 of the License, or (at your
 # option) any later version.
-#
 
 emulate -LR zsh
 setopt extendedglob
@@ -117,28 +116,54 @@
 _hg_get_commands() {
   typeset -ga _hg_cmd_list
   typeset -gA _hg_alias_list
-  local hline cmd cmdalias
-  _call_program help hg --verbose help | while read -A hline
+  local hline cmd cmdalias helpstate
+  local helpmode=$1
+
+  _call_program help hg --verbose help $helpmode 2>/dev/null | while read -A hline
   do
-    cmd="$hline[1]"
-    case $cmd in
-      *:)
-        cmd=${cmd%:}
-        _hg_cmd_list+=($cmd)
-      ;;
-      *,)
-        cmd=${cmd%,}
-        _hg_cmd_list+=($cmd)
-        integer i=2
-        while (( i <= $#hline ))
-        do
-          cmdalias=${hline[$i]%(:|,)}
-          _hg_cmd_list+=($cmdalias)
-          _hg_alias_list+=($cmdalias $cmd)
-          (( i++ ))
-        done
-      ;;
-    esac
+    if [ "$hline" = "list of commands:" ]
+    then
+      helpstate="commands"
+      continue
+    elif [ "$hline" = "enabled extensions:" ]
+    then
+      helpstate="extensions"
+      continue
+    elif [ "$hline" = "additional help topics:" ]
+    then
+      helpstate="topics"
+      continue
+    fi
+
+    if [ "$helpstate" = commands ]
+    then
+      cmd="$hline[1]"
+      case $cmd in
+        *:)
+          cmd=${cmd%:}
+          _hg_cmd_list+=($cmd)
+        ;;
+        *,)
+          cmd=${cmd%,}
+          _hg_cmd_list+=($cmd)
+          integer i=2
+          while (( i <= $#hline ))
+          do
+            cmdalias=${hline[$i]%(:|,)}
+            _hg_cmd_list+=($cmdalias)
+            _hg_alias_list+=($cmdalias $cmd)
+            (( i++ ))
+          done
+        ;;
+      esac
+    elif [ -z "$helpmode" -a "$helpstate" = extensions ]
+    then
+      cmd="$hline[1]"
+      if [ -n "$cmd" ]
+      then
+        _hg_get_commands $cmd
+      fi
+    fi
   done
 }