contrib/bash_completion
changeset 1555 01a5121a005a
parent 1339 f351d1a07d75
child 1556 561b17b7d3a2
--- a/contrib/bash_completion	Thu Nov 17 19:38:57 2005 +0100
+++ b/contrib/bash_completion	Wed Nov 23 08:02:35 2005 +0100
@@ -2,18 +2,25 @@
 
 _hg_commands()
 {
-    local commands="$(hg -v help | sed -e '1,/^list of commands:/d' \
-				       -e '/^global options:/,$d' \
-				       -e '/^ [^ ]/!d; s/[,:]//g;')"
+    local all commands result
+
+    all=($(hg --debug help | sed -e '1,/^list of commands:/d' \
+				 -e '/^global options:/,$d' \
+				 -e '/^ [^ ]/!d; s/^ //; s/[,:]//g;'))
+    
+    commands="${all[*]##debug*}"
+    result=$(compgen -W "${commands[*]}" -- "$cur")
 
     # hide debug commands from users, but complete them if
-    # specifically asked for
-    if [[ "$cur" == de* ]]; then
-	commands="$commands debugcheckstate debugstate debugindex"
-	commands="$commands debugindexdot debugwalk debugdata"
-	commands="$commands debugancestor debugconfig debugrename"
+    # there is no other possible command
+    if [ "$result" = "" ]; then
+	local debug
+	debug=(${all[*]##!(debug*)})
+	debug="${debug[*]/g/debug}"
+	result=$(compgen -W "$debug" -- "$cur")
     fi
-    COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$commands" -- "$cur") )
+
+    COMPREPLY=(${COMPREPLY[@]:-} $result)
 }
 
 _hg_paths()