summaryrefslogtreecommitdiff
path: root/git-shell-commands/help
blob: f3454023113016a76f310527b242f69adb17eaa1 (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 change-owner

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