Created
August 9, 2014 11:49
-
-
Save meoow/62a4a3b303543bed1a5d to your computer and use it in GitHub Desktop.
zimwriterfs shell wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# index icon dir file.zim | |
abspath(){ #{{{ | |
local thePath | |
if [[ ! "$1" =~ ^/ ]];then | |
thePath="$PWD/$1" | |
else | |
thePath="$1" | |
fi | |
echo "$thePath"|( | |
IFS=/ | |
read -a parr | |
declare -a outp | |
for i in "${parr[@]}";do | |
case "$i" in | |
''|.) continue ;; | |
..) | |
len=${#outp[@]} | |
if ((len==0));then | |
continue | |
else | |
unset outp[$((len-1))] | |
fi | |
;; | |
*) | |
len=${#outp[@]} | |
outp[$len]="$i" | |
;; | |
esac | |
done | |
echo /"${outp[*]}" | |
) | |
} #}}} | |
while [[ -n "$1" ]];do #{{{ | |
case "$1" in | |
-p|--page) shift; index="$1" ;; | |
-p?*) index="${1/-p}" ;; | |
-i|--icon) shift; icon="$1" ;; | |
-i?*) icon="${1/-i}" ;; | |
-d|--dir) shift; dir="$1" ;; | |
-d?*) dir="${1/-d}" ;; | |
-o|--output) shift; output="$1" ;; | |
-o?*) output="${1/-o}" ;; | |
*) if [[ -z "$index" ]];then | |
index="$1" | |
elif [[ -z "$icon" ]];then | |
icon="$1" | |
elif [[ -z "$dir" ]];then | |
dir="$1" | |
elif [[ -z "$output" ]];then | |
output="$1" | |
fi | |
;; | |
esac | |
shift | |
done #}}} | |
dir="$(abspath "$dir")" | |
if [[ ! -d "$dir" ]];then | |
exit 1 | |
fi | |
if [[ -f "$index" ]];then | |
index="$(abspath "$index")" | |
index="${index/$dir\/}" | |
fi | |
if [[ "$icon" == - ]];then #{{{ | |
cat <<_EOF_|base64 -D -o "$dir/icon.png" | |
iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAD8GlDQ1BJQ0MgcHJvZmlsZQAAOI2NVd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BXTIIt7xRFxSBxnuJWfuAd1I7jntkyd/pgKaIwVr3MgmDo2q8x6IdB5QH162mcX7ajtnHGN2bov71OU1+U0fqqoXLD0wX5ZM005UHmySz3qLtDqILDvIL+iH6jB9y2x83ok898GOPQX3lk3Itl0A+BrD6D7tUjWh3fis58BXDigN9yF8M5PJH4B8Gr79/F/XRm8m241mw/wvur4BGDj42bzn+Vmc+NL9L8GcMn8F1kAcXiS7a1/AAAACXBIWXMAAAsSAAALEgHS3X78AAAAGklEQVRYhe3BAQEAAACCIP+vbkhAAQAAAO8GECAAAUcBoIgAAAAASUVORK5CYII= | |
_EOF_ | |
icon=icon.png | |
else | |
if [[ -f "$icon" ]];then | |
icon="$(abspath "$icon")" | |
icon="${icon/$dir\/}" | |
fi | |
fi #}}} | |
if [[ ! "$output" =~ \.zim$ ]];then | |
output="$output".zim | |
fi | |
title="${output%.zim}" | |
des="${output%.zim}" | |
exec $(dirname "$0")/zimwriterfs --welcome="$index" --favicon="$icon" --language=eng --title="$title" --description="$des" --creator=meow --publisher=meow "$dir" "$output" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment