summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jh-help.sh30
-rw-r--r--jh-list-commands.sh16
-rw-r--r--jh-mvn-basename.sh3
-rw-r--r--jh-mvn-install.sh3
-rw-r--r--jh-mvn-localrepo.sh9
-rw-r--r--jh.sh41
6 files changed, 54 insertions, 48 deletions
diff --git a/jh-help.sh b/jh-help.sh
index 31fbf6e..8986abc 100644
--- a/jh-help.sh
+++ b/jh-help.sh
@@ -1,8 +1,30 @@
#!/bin/bash
-. jh
+
+stem=jh
+
+master_help() {
+ echo "Usage: $jh_short <command> [command-specific-arguments]"
+ echo "Java helper for PKGBUILDs"
+ echo ""
+ jh-list-commands|sed 's/./ &/'
+}
+
+generic_help() {
+ local cmd=$1
+ cmd=${cmd##*/}
+ cmd=${cmd#$stem-}
+
+ file=`find ${PATH//:/ } -type f -name "$stem-$cmd.help.txt" 2>/dev/null`
+ if [[ -r $file ]]; then
+ sed "s|@cmd@|$jh_short|g" "$file"
+ else
+ echo "$jh_short: Cannot find help file for '$cmd'" >> /dev/stderr
+ exit 1
+ fi
+}
case $# in
- 0) usage ''; exit 0;;
- 1) usage "$1"; exit 0;;
- *) usage help; exit 1;;
+ 0) master_help; exit 0;;
+ 1) generic_help "$1"; exit 0;;
+ *) generic_help help; exit 1;;
esac
diff --git a/jh-list-commands.sh b/jh-list-commands.sh
index 143f6e7..66ce5aa 100644
--- a/jh-list-commands.sh
+++ b/jh-list-commands.sh
@@ -1,13 +1,17 @@
#!/bin/bash
-. jh
if [[ $# > 0 ]]; then
- usage
+ jh-help $0 >>/dev/stderr
exit 1
fi
-for cmd_help in "$JH_PATH"/*.help.txt; do
- cmd=`echo "$cmd_help"|sed -r 's|.*/jh-(.*)\.help\.txt$|\1|'`
+stem=jh
+
+find ${PATH//:/ } -type f -name "$stem-*.help.txt" 2>/dev/null |
+while read cmd_help; do
+ cmd=$cmd_help
+ cmd=${cmd%.help.txt}
+ cmd=${cmd##*/$stem-}
help=`sed -n 2p "$cmd_help"`
- printf "%-20s %s\n" "$cmd" "$help"
-done
+ printf '%-20s %s\n' "$cmd" "$help"
+done | sort
diff --git a/jh-mvn-basename.sh b/jh-mvn-basename.sh
index 776cc0e..eff78aa 100644
--- a/jh-mvn-basename.sh
+++ b/jh-mvn-basename.sh
@@ -1,8 +1,7 @@
#!/bin/bash
-. jh
if [[ $# != 3 ]]; then
- usage
+ jh-help $0 >>/dev/stderr
exit 1
fi
diff --git a/jh-mvn-install.sh b/jh-mvn-install.sh
index 23c0d6a..41aefcc 100644
--- a/jh-mvn-install.sh
+++ b/jh-mvn-install.sh
@@ -1,8 +1,7 @@
#!/bin/bash
-. jh
if [[ $# != 5 ]]; then
- usage
+ jh-help $0 >>/dev/stderr
exit 1
fi
diff --git a/jh-mvn-localrepo.sh b/jh-mvn-localrepo.sh
index 14ea778..e74e7a9 100644
--- a/jh-mvn-localrepo.sh
+++ b/jh-mvn-localrepo.sh
@@ -1,13 +1,12 @@
#!/bin/bash
-. jh
if [[ $# > 0 ]]; then
- usage
- exit 1
+ jh-help $0 >>/dev/stderr
+ exit 1
fi
if [ -e /etc/maven/settings.xml ]; then
- xml sel -T -t -v "//*[local-name()='localRepository']" -n /etc/maven/settings.xml
+ xml sel -T -t -v "//*[local-name()='localRepository']" -n /etc/maven/settings.xml
else
- echo /usr/share/maven/repository
+ echo /usr/share/maven/repository
fi
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 "$@"