2022-04-06 12:27:26 -07:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
minimize () {
|
|
|
|
# will minimize script, removing comment lines and blank lines and inline comments
|
|
|
|
# TODO -r remove shebang, replace newlines with ; remove continuation \
|
|
|
|
# usage: <options> "source" (source as text or source as filename, as text MUST be quoted!)
|
|
|
|
# options:
|
|
|
|
# -t # argment will get text of source, otherwise it is the file path
|
|
|
|
# -o filepath # output to file
|
|
|
|
# -v # verbose, only applies when using -o. will output to file and return (stdout).
|
|
|
|
local out; local verbose; local text
|
2023-12-17 12:54:45 -08:00
|
|
|
local min="/^[[:space:]]*#/d; /#$/d; /^$/d"
|
2022-04-06 12:27:26 -07:00
|
|
|
local OPTION; local OPTARG; local OPTIND
|
|
|
|
while getopts 'to:v' OPTION; do
|
|
|
|
# echo $OPTION $OPTARG
|
|
|
|
case "$OPTION" in
|
|
|
|
|
|
|
|
t)
|
|
|
|
text=true
|
|
|
|
;;
|
|
|
|
v)
|
|
|
|
verbose=true
|
|
|
|
;;
|
|
|
|
o)
|
|
|
|
out="$OPTARG"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo unknown option $OPTION
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $((OPTIND - 1))
|
|
|
|
|
|
|
|
if [[ $text ]]; then
|
|
|
|
res="$(echo "$1" | sed "$min")"
|
|
|
|
else
|
|
|
|
res="$(sed "$min" "$1")"
|
2023-12-17 12:54:45 -08:00
|
|
|
# ; s/\(.*\)#.*/\1/"
|
|
|
|
# | sed -z 's/\n/;/g' | sed 's/;$/\n/' | tr -s ' ' | sed 's/{;/{\n/g' | sed 's/;};/\n}\n/g')"
|
2022-04-06 12:27:26 -07:00
|
|
|
fi
|
2023-12-17 12:54:45 -08:00
|
|
|
out=${out:-$2}
|
2022-04-06 12:27:26 -07:00
|
|
|
if [[ $out ]]; then
|
|
|
|
[[ $verbose ]] && echo "$res" | tee "$out" || echo "$res" > "$out"
|
|
|
|
else
|
|
|
|
echo "$res"
|
|
|
|
fi
|
|
|
|
}
|