~ecs/tm

357d4f26209d30566194295c6e76216e4ab89ee9 — Ember Sawady 3 years ago cbf50ba
tm: improve error message on invalid command
2 files changed, 8 insertions(+), 5 deletions(-)

M lib.sh
M tm
M lib.sh => lib.sh +1 -1
@@ 29,7 29,7 @@ isignored() {

postfix() {
	len="$(printf "%s" "$1" | wc -c)"
	IFS= while read -r "line"; do
	while IFS= read -r "line"; do
		linelen="$(printf "%s" "$line" | wc -c)"
		post="$(printf "%s" "$line" | cut -c"$((linelen - len + 1))-" 2>/dev/null || true)"
		[ "z$post" = "z$1" ] && printf "%s\n" "$line"

M tm => tm +7 -4
@@ 1,15 1,18 @@
#!/bin/sh -eu

if [ $# -eq 0 ]; then
usage() {
	echo "usage: tm command [subcommand...]"
	# TODO: list subcommands?
	exit
fi
	exit 1
}

[ $# -eq 0 ] && usage
cd "$(dirname -- "$0")"
export PATH="$PWD:$PATH"
cd - >/dev/null
. "$(dirname -- "$0")/lib.sh"
cmd="$1"
shift
# TODO: better error message on invalid command
which tm-"$cmd" >/dev/null 2>/dev/null || abort "error: invalid command $cmd
$(usage)"
exec tm-"$cmd" "$@"