summaryrefslogtreecommitdiff
path: root/jh.sh
diff options
context:
space:
mode:
Diffstat (limited to 'jh.sh')
-rw-r--r--jh.sh41
1 files changed, 12 insertions, 29 deletions
diff --git a/jh.sh b/jh.sh
index 6886e4a..ca580a3 100644
--- a/jh.sh
+++ b/jh.sh
@@ -1,45 +1,28 @@
#!/bin/bash
-if [[ -z "$jh_cmd" ]]; then
- export jh_cmd=$0
-fi
-export jh_short=${jh_cmd##*/}
-
-if [[ -z "$JH_PATH" ]]; then
+if [[ -z $JH_PATH ]]; then
export JH_PATH=/usr/share/jh
fi
-usage() {
- cmd="${1-$0}"
- cmd="${cmd##*/jh-}"
- file="$JH_PATH/jh-$cmd.help.txt"
- if [[ -z "$cmd" ]]; then
- echo "Usage: $jh_short <command> [command-specific-arguments]"
- echo "Java helper for PKGBUILDs"
- echo ""
- "$jh_short" list-commands|sed 's/./ &/'
- elif [[ -f "$JH_PATH/jh-$cmd.help.txt" ]]; then
- sed "s|@cmd@|$jh_short|g" "$file" >> /dev/stderr
- else
- echo "$jh_short: Cannot find help file for '$cmd'" >> /dev/stderr
- fi
-}
+if [[ -z $jh_short ]]; then
+ export jh_short=${0##*/}
+ export PATH="$JH_PATH:$PATH"
+fi
-run() {
+main() {
if [[ $# < 1 ]]; then
- usage ''
- exit 1;
+ jh-help >>/dev/stderr
+ return 1;
fi
cmd=$1
shift
- file="$JH_PATH/jh-$cmd"
- if [[ -x "$file" ]]; then
- "$file" "$@"
- exit $?
+ if [[ -x "$(which "jh-$cmd" 2>/dev/null)" ]]; then
+ "jh-$cmd" "$@"
+ return $?
else
echo "$jh_short: Cannot find command '$cmd'" >> /dev/stderr
fi
}
-[[ "$jh_cmd" == "$0" ]] && run "$@"
+main "$@"