diff contrib/bash_completion @ 1584:b3e94785ab69

merge with crew
author Vadim Gelfer <vadim.gelfer@gmail.com>
date Sun, 11 Dec 2005 15:38:42 -0800
parents 561b17b7d3a2
children 851bc33ff545
line wrap: on
line diff
--- a/contrib/bash_completion
+++ b/contrib/bash_completion
@@ -2,18 +2,25 @@ shopt -s extglob
 
 _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()
@@ -161,7 +168,7 @@ shopt -s extglob
 	    fi
 	;;
 	*)
-            COMPREPLY=(${COMPREPLY[@]:-} $( compgen -f -- "$cur" ))
+	    COMPREPLY=(${COMPREPLY[@]:-} $( compgen -f -- "$cur" ))
 	;;
     esac