3 # Show help for Cogito commands
4 # Copyright (c) Petr Baudis, 2005
6 # Takes an optional argument describing the command to show the help for.
7 # The command can be specified either as 'COMMAND' or 'cg-COMMAND'.
8 # If the argument is left out an overview of all the Cogito commands will
11 # Note, short help for a command is also available by passing `--help` or
12 # `-h` to the command. The complete command manual is shown when passing
13 # `--long-help` (and is the same as doing "`cg-help command`").
18 # Colorize the output. You can customize the colors using the
19 # $CG_COLORS environment variable (see below).
21 # ENVIRONMENT VARIABLES
22 # ---------------------
24 # The pager to display log information in, defaults to `less`.
27 # Flags to pass to the pager.
30 # Colon-separated list of 'name=color' pairs, where name is
31 # one of helpcopy, helpusage, helpsection, helplitem, helpcgcmd,
32 # helpcode, helpempth, default, and value is an ECMA-48 SGR
33 # sequence (see e.g. console_codes(4)).
36 # Even if -c was passed or specified in ~/.cgrc, if this option
37 # is set, use colors only when the output is a terminal and it
41 # This is what the $LESS environment variable value will be set
42 # to before invoking $PAGER. It defaults to $LESS concatenated
43 # with the `R` flag to allow displaying of colorized output.
45 # CONFIGURATION VARIABLES
46 # -----------------------
47 # The following GIT configuration file variables are recognized:
50 # If enabled, colorify the output like with -c if the output
55 USAGE
="cg-help [-c] [cg-COMMAND | COMMAND]"
58 .
"${COGITO_LIB}"cg-Xlib ||
exit 1
62 local C
="helpcopy=34:helpusage=33"
63 C
="$C:helpsection=35:helplitem=33"
64 C
="$C:helpcgcmd=32:helpcode=36"
70 s/^\(-.*\)::.*/$colhelplitem\1$coldefault:/
71 s/^\(.*\)::/$colhelplitem\1$coldefault:/
72 s/\`\(cg-[a-z-]*\)\`/$colhelpcgcmd\1$coldefault/g
73 s/\`\([^\`]*\)\`/$colhelpcode&$coldefault/g
74 s/[^A-Z0-9a-z_-]\$ .*/$colhelpcode&$coldefault/g
75 s/'\([^ ]*\)'/$colhelpemph&$coldefault/g
76 s/'\(-[A-Z0-9a-z_-]* [^']*\)'/$colhelpemph&$coldefault/g
77 s/^Usage: .*/$colhelpusage&$coldefault/
78 /^[A-Z -_]*/,/^---*$/s/^[A-Z -_]*\$/$colhelpsection&$coldefault/
79 s/^Copyright .*/$colhelpcopy&$coldefault/
83 print_command_listing
()
85 width
="$(IFS=$'\n'; echo "$
*" | column_width "$bin_path/" 25)"
86 for command in "$@"; do
87 [ -f "$command" ] ||
continue
88 if [ -L "$command" ]; then
89 tg
="$(readlink "$command")"
90 # Skip symlinks within the same directory, those are
91 # aliases; symlinks to elsewhere are permitted since
92 # they may be created by some weirder packaging sys.
93 [ z
"${tg#*/}" != z
"$tg" ] ||
continue
95 cmdname
="${command#$bin_path/}"
97 shortdesc
="$(sed -n 'n;n;p;q' <"$command")"
98 # Some minimal sanity check that we didn't pick up some
99 # random binary named cg-*
100 [ "${shortdesc:0:1}" = "#" ] ||
continue
101 columns_print
'' t-
"$cmdname" $width " ${shortdesc:2}"
106 sed -e "$apply_colors" | pager
120 colorify_detect
"$colors" help && setup_colors
121 bin_path
="$(dirname "$0")"
124 if [ "$ARGS" = "admin" ]; then
125 echo "The advanced (low-level, dangerous, or administrative) commands:"
126 IFS
=$
'\n' print_command_listing $
(ls "$bin_path"/cg-admin
*)
128 elif [ "$ARGS" = "branch" ]; then
129 echo "The branch commands family:"
130 IFS
=$
'\n' print_command_listing $
(ls "$bin_path"/cg-branch
*)
132 elif [ "$ARGS" = "tag" ]; then
133 echo "The tag commands family:"
134 IFS
=$
'\n' print_command_listing $
(ls "$bin_path"/cg-tag
*)
136 elif [ "$ARGS" ]; then
137 cmd
="$(echo "${ARGS[0]}" | sed 's/^cg-//')"
138 print_help long
"$cmd" | colorize
139 [ "${PIPESTATUS[0]}" -eq 0 ] && exit
140 echo "cg-help: no help available for command \"${ARGS[0]}\""
141 echo "Call cg-help without any arguments for the list of available commands"
146 REGULAR_COMMANDS
="$(ls "$bin_path"/cg-* | grep -v /cg-X | grep -v /cg-admin | grep -v /cg-branch | grep -v /cg-tag)"
147 # TODO: Some uberevil `column` tricks...
148 BRANCH_COMMANDS
="$(ls "$bin_path"/cg-branch* | sed 's#.*/##' | tr '\n' ' ')"
149 TAG_COMMANDS
="$(ls "$bin_path"/cg-tag* | sed 's#.*/##' | tr '\n' ' ')"
150 ADVANCED_COMMANDS
="$(ls "$bin_path"/cg-admin-* | sed 's#.*/##' | tr '\n' ' ')"
152 IFS
=$
'\n' colorize
<<__END__
153 The Cogito version control system $(cg-version)
155 Available regular commands:
156 $(print_command_listing $REGULAR_COMMANDS)
158 Special command families:
159 cg-help admin ($ADVANCED_COMMANDS\b)
160 cg-help branch ($BRANCH_COMMANDS\b)
161 cg-help tag ($TAG_COMMANDS\b)
163 These expressions can be used interchangeably as "ID"s:
164 empty string, "this" or "HEAD" (current HEAD)
165 branch name (as registered with cg-branch-add)
166 tag name (as registered with cg-tag)
167 date string (as recognized by the date tool)
168 shortcut hash (shorted unambiguous hash lead)
169 commit object hash (as returned by cg-object-id -c)
170 tree object hash (accepted only by some commands)
172 For details on individual commands, do e.g.:
175 (both variants are equivalent)