summaryrefslogtreecommitdiff
path: root/git-shell-commands/help
blob: 0792cb59d65b4c33fd6373b7a8e492736365d51f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env bash
# * help [COMMAND]
#   Get enabled commands
#   Example: help
#   Example: help create-bare-repo

set -e

HOSTNAME=git.parabola.nu

if [[ "$*" = */* ]]; then
	printf 'Command names may not contain /\n'
	exit 1
fi

if test $# = 0; then
	cmds=("$(dirname "$0")"/*)
else
	cmds=("${@/#/"$(dirname "$0")/"}")
fi

# Gets the initial comment after the shebeng from every git-shell-command
for c in "${cmds[@]}"; do
	sed -rn '2,/^[^#]/s/^# ?//p' "$c"
	echo
done |
if test -z "$TERM" || test "$TERM" = dumb; then
	sed "s/Example: /&ssh $USER@$HOSTNAME /"
else
	cat
fi