Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 52 lines (44 sloc) 1.14 KB
#!/usr/bin/env bash
set -e
print_summaries() {
for file in $_AG_ROOT/libexec/a-*; do
if [ ! -h $file ]; then
local summary=$(grep "^# Summary:" $file | cut -d ' ' -f3-)
if [ -n "$summary" ]; then
local name=$(basename $file | sed 's/a-//')
echo "$name" | awk '{ printf " %-20s ", $1}'
echo -n $summary
echo
fi
fi
done
}
print_help() {
local usage=$(grep "^# Usage:" $1 | cut -d ' ' -f2-)
local halp="$(awk '/^# Help:/,/^[^#]/' $1 | grep "^#" | sed "s/^# Help: //" | sed "s/^# //" | sed "s/^#//")"
if [ -n "$usage" ]; then
echo $usage
[ -n "$halp" ] && echo && echo "$halp"
else
echo "Sorry, this command isn't documented yet."
fi
}
# Provide a completions
if [ "$1" = "--complete" ]; then
exec "a-commands"
exit
fi
case "$1" in
"") echo "Usage: a <command> [<args>]
Some useful a commands are:
$(print_summaries)
See 'a help <command>' for information on a specific command."
;;
*)
command_path="$(command -v "$_AG_ROOT/libexec/a-$1" || true)"
if [ -n "$command_path" ]; then
print_help "$_AG_ROOT/libexec/a-$1"
else
echo "a: no such command \`$1'"
fi
esac