aboutsummaryrefslogtreecommitdiff
path: root/status
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2017-07-27 12:38:43 -0300
committerSilvio Rhatto <rhatto@riseup.net>2017-07-27 12:38:43 -0300
commit1b09cefd5abe824ce545de343e9eddcda4d6c7b5 (patch)
treeaae20c0886281caf8e0fdd10937122649f66231a /status
parent8b3d6363b901ebac30d858911191f4fc848e39d3 (diff)
downloadscripts-1b09cefd5abe824ce545de343e9eddcda4d6c7b5.tar.gz
scripts-1b09cefd5abe824ce545de343e9eddcda4d6c7b5.tar.bz2
Status: use getopt
Diffstat (limited to 'status')
-rwxr-xr-xstatus62
1 files changed, 58 insertions, 4 deletions
diff --git a/status b/status
index a9a05a7..105cf75 100755
--- a/status
+++ b/status
@@ -4,8 +4,59 @@
#
# Parameters
-PROJECT="$1"
-DELAY="$2"
+BASENAME="`basename $0`"
+
+# Usage
+function status_usage {
+ echo "usage: $BASENAME [-l|--long] [-d|--delay N] [project]"
+
+ if [ -z "$1" ]; then
+ exit 1
+ else
+ exit $1
+ fi
+}
+
+# See https://stackoverflow.com/questions/2721946/cross-platform-getopt-for-a-shell-script#4300224
+function status_options {
+ getopt -T > /dev/null
+ if [ $? -eq 4 ]; then
+ # GNU enhanced getopt is available
+ ARGS=`getopt --name "$BASENAME" --long loop,delay: --options ld: -- "$@"`
+ else
+ # Original getopt is available (no long option names, no whitespace, no sorting)
+ ARGS=`getopt ld: "$@"`
+ fi
+
+ if [ $? -ne 0 ]; then
+ echo "$BASENAME: usage error" >&2
+ status_usage 2
+ fi
+
+ eval set -- $ARGS
+
+ while [ $# -gt 0 ]; do
+ case "$1" in
+ l|--loop)
+ LOOP="yes";;
+ d|--delay)
+ DELAY="$2"
+ shift;;
+ --)
+ shift
+ break;;
+ *)
+ status_usage
+ ;;
+ esac
+ shift
+ done
+
+ if [ $# -gt 0 ]; then
+ PROJECT="$1"
+ shift
+ fi
+}
# Run status
function status_run {
@@ -42,8 +93,11 @@ function status_run {
fi
}
+# Options
+status_options $@
+
# Dispatch
-if [ "$PROJECT" == "--loop" ]; then
+if [ "$LOOP" == "yes" ]; then
PROJECT=""
if [ -z "$DELAY" ]; then
@@ -51,9 +105,9 @@ if [ "$PROJECT" == "--loop" ]; then
fi
while true; do
+ clear
status_run
sleep $DELAY
- clear
done
else
status_run