git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/3] generate-cmdlist.sh: parse common group commands

From
Sébastien Guimmara <sebastien.guimmara@gmail.com>
Date
May 4, 2015, 20:28 UTC
Message-ID
<a787babf25481c99edea6dca5e5f7814601395fe.1430770308.git.sebastien.guimmara@gmail.com>
In-Reply-To
<cover.1430770308.git.sebastien.guimmara@gmail.com>
parse the [groups] block to create the array of group descriptions
   static char *common_cmd_groups[] = {
      N_("starting a working area"),
      N_("working on the current change"),
      N_("working with others"),
      N_("examining the history and state"),
      N_("growing, marking and tweaking your history"),
   };
then map each element of common_cmds[] to a group via its index:
   static struct cmdname_help common_cmds[] = {
     {"add", N_("Add file contents to the index"), 1},
     {"branch", N_("List, create, or delete branches"), 4},
     {"checkout", N_("Checkout a branch or paths to the working tree"), 4},
     {"clone", N_("Clone a repository into a new directory"), 0},
     {"commit", N_("Record changes to the repository"), 4},
     [...]
So that 'git help' can print those command grouped by theme.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Sébastien Guimmara <sebastien.guimmara@gmail.com>
---
 generate-cmdlist.sh | 43 +++++++++++++++++++++++++++++++------------
 1 file changed, 31 insertions(+), 12 deletions(-)
diff --git a/generate-cmdlist.sh b/generate-cmdlist.sh
index 9a4c9b9..724bb8d 100755
--- a/generate-cmdlist.sh
+++ b/generate-cmdlist.sh
@@ -1,23 +1,42 @@
 #!/bin/sh
+content=$(cat command-list.txt)
+
+group_line_no=$(expr $(echo "$content" | grep -n '^\[groups\]' | cut -f1 -d:) + 1)
+command_line_no=$(expr $(echo "$content" | grep -n '^\[commands\]' | cut -f1 -d:) + 1)
+groups=$(echo "$content" | sed -n ''$group_line_no', '$(expr $command_line_no)'p')
 
 echo "/* Automatically generated by $0 */
+
 struct cmdname_help {
     char name[16];
     char help[80];
+    unsigned char group;
 };
 
+static char *common_cmd_groups[] = {"
+echo "$groups" |
+while read group description; do
+    if [ -z $group ]; then
+        break
+    fi
+    echo '   N_("'$description'"),'
+done
+echo "};
+
 static struct cmdname_help common_cmds[] = {"
 
-sed -n -e 's/^git-\([^ 	]*\)[ 	].* common.*/\1/p' command-list.txt |
-sort |
-while read cmd
-do
-     sed -n '
-     /^NAME/,/git-'"$cmd"'/H
-     ${
-	    x
-	    s/.*git-'"$cmd"' - \(.*\)/  {"'"$cmd"'", N_("\1")},/
-	    p
-     }' "Documentation/git-$cmd.txt"
+echo "$content" | grep 'common-' |
+awk '{ print $1, "\t", $3 }' |
+while read cmd grp; do
+    cmd_name=$(echo $cmd | cut -d - -f 2)
+    group_name=$(echo $grp | cut -d - -f 2)
+    group_idx=$(expr $(echo "$groups" | grep -n "^$group_name" | cut -c 1) - 1)
+    sed -n '
+    /^NAME/,/git-'"$cmd_name"'/H
+    ${
+       x
+       s/.*git-'"$cmd_name"' - \(.*\)/  {"'"$cmd_name"'", N_("\1"), '"$group_idx"'},/
+       p
+    }' "Documentation/$cmd.txt"
 done
-echo "};"
+echo "};"
\ No newline at end of file
-- 
2.4.0
Previous: Eric SunshineNext: Eric Sunshine
Message 12 of 38 in “git help: group common commands by theme”
  1. 0/3 git help: group common commands by themeSébastien Guimmara, May 4, 2015
  2. 1/3 command-list.txt: group common commands by themeSébastien Guimmara, May 4, 2015
  3. Eric SunshineMay 6, 2015
  4. Sébastien GuimmaraMay 6, 2015
  5. Eric SunshineMay 7, 2015
  6. Johannes SixtMay 7, 2015
  7. Johannes SchindelinMay 8, 2015
  8. Andreas SchwabMay 8, 2015
  9. Johannes SchindelinMay 8, 2015
  10. Sébastien GuimmaraMay 8, 2015
  11. Eric SunshineMay 8, 2015
  12. 2/3 generate-cmdlist.sh: parse common group commandsSébastien Guimmara, May 4, 2015
  13. Eric SunshineMay 8, 2015
  14. Eric SunshineMay 8, 2015
  15. Sébastien GuimmaraMay 8, 2015
  16. 3/3 git help: group common commands by themeSébastien Guimmara, May 4, 2015
  17. Eric SunshineMay 6, 2015
  18. Sébastien GuimmaraMay 6, 2015
  19. Sébastien GuimmaraMay 8, 2015
  20. Stefan BellerMay 8, 2015
  21. Eric SunshineMay 8, 2015
  22. Sébastien GuimmaraMay 8, 2015
  23. Eric SunshineMay 6, 2015
  24. Sébastien GuimmaraMay 6, 2015
  25. Eric SunshineMay 6, 2015
  26. Junio C HamanoMay 6, 2015
  27. Sébastien GuimmaraMay 8, 2015
  28. Junio C HamanoMay 8, 2015
  29. Matthieu MoyMay 6, 2015
  30. Junio C HamanoMay 6, 2015
  31. Matthieu MoyMay 7, 2015
  32. Junio C HamanoMay 7, 2015
  33. Matthieu MoyMay 8, 2015
  34. Junio C HamanoMay 8, 2015
  35. Emma Jane Hogbin WestbyMay 7, 2015
  36. Sébastien GuimmaraMay 8, 2015
  37. Junio C HamanoMay 8, 2015
  38. Sébastien GuimmaraMay 8, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.