From 96d91a9aeb765bc5ca2398c3591e83c59d6a4c71 Mon Sep 17 00:00:00 2001 From: "sh+git@codevoid.de" Date: Sun, 27 Oct 2019 13:42:02 +0000 Subject: [PATCH] Support CLI Options --- Makefile | 2 +- mkpicindex-static.sh | 41 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 4f88ce6..8033dea 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ all: ./mkpicindex.sh > index.html.tmp && mv index.html.tmp index.html static: - ./mkpicindex-static.sh 0 > index.html.tmp && mv index.html.tmp index.html + ./mkpicindex-static.sh > index.html.tmp && mv index.html.tmp index.html clean: rm -rf index.html.tmp index.html style.css justify.js LICENSE diff --git a/mkpicindex-static.sh b/mkpicindex-static.sh index 6ce992e..985e142 100755 --- a/mkpicindex-static.sh +++ b/mkpicindex-static.sh @@ -11,8 +11,8 @@ printf '%s' \ # CONFIGURE TITLE="My Gallery" # browser title -WIDTH=1000 # how wide will the gallery be -ROW_HEIGHT=150 # how high will the justified rows be? +WIDTH=850 # how wide will the gallery be +ROW_HEIGHT=180 # how high will the justified rows be? THUMB_QUALITY=83 # quality for thumbnails THUMB_PATH="thm" # relative path to thumbnail folder THUMB_PADDING="6" # image padding @@ -21,6 +21,41 @@ THUMB_PADDING="6" # image padding DEBUG=0 # debug output THREADS=4 +# PRINT HELP / USAGE TEXT +usage() { + printf '%s\n' \ +'Usage: mkpicindex [option] > outfile.html + Options: + -t "My Gallery" - Title + -w 850 - Width + -h 180 - Row height + -q 83 - Thumbnail quality + -b 6 - Thumbnail border + -p 8 - Max convert processes + -d - Debug mode + -h - This help +' + exit 2 +} + +# OVERIDE DEFAULTS +while getopts 't:w:h:b:q:p:d' c +do + case $c in + t) TITLE="$OPTARG" ;; + w) WIDTH="$OPTARG" ;; + h) ROW_HEIGHT="$OPTARG" ;; + q) QUALITY="$OPTARG" ;; + b) THUMB_PADDING="$OPTARG" ;; + p) THREADS="$OPTARG" ;; + d) DEBUG=1 ;; + ?|*) usage; ;; + esac +done + +# PRINT USAGE IF OUTPUT IS NOT REDIRECTED +[ "$DEBUG" != 1 ] && test -t 1 && usage; + # GLOBAL TMP VARIABLES G_ROW_WIDTH=0 # combined pic width < WIDTH @ ROW_HEIGHT G_ROW_FILES="" # pipe separated files < WIDTH @@ -139,7 +174,7 @@ printf '%s\n' \ ' - My Gallery + '"$TITLE"'