Benno Schulenberg wrote:
> Attached patch prints the builtin commands alphabetically per
> column and uses a total width of 80 characters.

Here is a better patch.  It also puts a ">" in the last column 
position of the strings that are longer than the available width.

To find the width of the current terminal I will need some help, 
though.  Or if you think a variable width isn't worth the trouble, 
just leave out the two width-limiting lines .

The second patch improves the summary line of the 'variables' item 
a bit, especially when the column width is somewhat limited.

Benno
diff -ur bash-3.2.orig/builtins/help.def bash-3.2.new/builtins/help.def
--- bash-3.2.orig/builtins/help.def	2004-12-30 19:59:55.000000000 +0100
+++ bash-3.2.new/builtins/help.def	2006-12-20 18:39:20.000000000 +0100
@@ -175,8 +175,8 @@
 static void
 show_builtin_command_help ()
 {
-  int i, j;
-  char blurb[36];
+  int i, j, k, height, width;
+  char blurb[71];
 
   printf (
 _("These shell commands are defined internally.  Type `help' to see this list.\n\
@@ -187,21 +187,26 @@
 A star (*) next to a name means that the command is disabled.\n\
 \n"));
 
-  for (i = 0; i < num_shell_builtins; i++)
+  height = (num_shell_builtins + 1) / 2;
+  width = 40;  /* XXX should use half of terminal width instead */
+  if (width > 70)
+    width = 70;  /* limit column width to this maximum */
+
+  for (i = 0; i < height; i++)
     {
       QUIT;
-      blurb[0] = (shell_builtins[i].flags & BUILTIN_ENABLED) ? ' ' : '*';
-      strncpy (blurb + 1, shell_builtins[i].short_doc, 34);
-      blurb[35] = '\0';
-      printf ("%s", blurb);
-
-      if (i % 2)
-	printf ("\n");
-      else
-	for (j = strlen (blurb); j < 35; j++)
-	  putc (' ', stdout);
+      for (k = i; k < num_shell_builtins; k += height)  /* two columns */
+	{
+	  blurb[0] = (shell_builtins[k].flags & BUILTIN_ENABLED) ? ' ' : '*';
+	  strncpy (blurb + 1, shell_builtins[k].short_doc, width - 1);
+	  if (strlen (shell_builtins[k].short_doc) >= width)
+	    blurb[width - 1] = '>';  /* indicate truncated string */
+	  blurb[width] = '\0';
+	  for (j = strlen (blurb); j < width; j++)
+	    blurb[j]=' ';  /* pad out any remaining width with spaces */
+	  printf ("%s", blurb);
+	}
+      printf ("\n");
     }
-  if (i % 2)
-    printf ("\n");
 }
 #endif /* HELP_BUILTIN */
diff -ur bash-3.2.orig/builtins/reserved.def bash-3.2.new/builtins/reserved.def
--- bash-3.2.orig/builtins/reserved.def	2006-03-07 20:30:00.000000000 +0100
+++ bash-3.2.new/builtins/reserved.def	2006-12-20 19:08:20.000000000 +0100
@@ -145,7 +145,7 @@
 
 $BUILTIN variables
 $DOCNAME variable_help
-$SHORT_DOC variables - Some variable names and meanings
+$SHORT_DOC variables - Names and meanings of some variables
 BASH_VERSION	Version information for this Bash.
 CDPATH	A colon-separated list of directories to search
 		for directries given as arguments to `cd'.
_______________________________________________
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash

Reply via email to