Fix bash_completion on Solaris
authorAlexis S. L. Carvalho <alexis@cecm.usp.br>
Tue, 28 Feb 2006 11:49:35 -0600
changeset 1805 2af98c4b2587
parent 1804 c3f959c1c3ff
child 1806 a2c69737e65e
Fix bash_completion on Solaris TK Soh noticed that the awk that ships with Solaris doesn't allow you to define new functions. According to http://www.shelldorado.com/articles/awkcompat.html it looks like it also doesn't have some other stuff that we were using, like deletion of an array element and gsub. Rewrite the parsing of hg --debug help to work around that. This version doesn't filter aliases that are simple abbreviations for debug commands (not a big problem, since there are none right now).
contrib/bash_completion
--- a/contrib/bash_completion	Sun Feb 26 16:23:14 2006 +0100
+++ b/contrib/bash_completion	Tue Feb 28 11:49:35 2006 -0600
@@ -3,23 +3,23 @@
 _hg_command_list()
 {
     "$hg" --debug help 2>/dev/null | \
-	awk 'function command_line(line) {
-		gsub(/,/, "", line)
-		gsub(/:.*/, "", line)
-		split(line, aliases)
-		command = aliases[1]
-		delete aliases[1]
+	awk -F', ' '/^list of commands:/ {commands=1}
+	    commands && /^ [^ ]/ {
+		sub(/ /, "")
+		sub(/:.*/, "")
+		command = $1
+		if (index(command, "debug") == 1) {
+		    for (i=1; i<=NF; i++)
+			debug[j++] = $i
+		    next
+		}
 		print command
-		for (i in aliases)
-		    if (index(command, aliases[i]) != 1)
-			print aliases[i]
+		for (i=2; i<=NF; i++)
+		    if (index(command, $i) != 1)
+			print $i
 	    }
-	    /^list of commands:/ {commands=1}
-	    commands && /^ debug/ {a[i++] = $0; next;}
-	    commands && /^ [^ ]/ {command_line($0)}
 	    /^global options:/ {exit 0}
-	    END {for (i in a) command_line(a[i])}'
-
+	    END {for (i in debug) print debug[i]}'
 }
 
 _hg_option_list()