Last active
January 22, 2017 15:11
-
-
Save victorfsf/a9cae416f5bbd47e71b141e72dd3b8e7 to your computer and use it in GitHub Desktop.
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 | |
if [ $# != 2 ] | |
then | |
echo "minify takes exactly 2 arguments ($# given)" | |
exit 1 | |
fi | |
case ${1} in | |
-f) | |
content=`cat $2` | |
;; | |
-t) | |
content="$2" | |
;; | |
*) | |
echo "Unknown option: $1" | |
exit 1 | |
;; | |
esac | |
# Removes comments and unnecessary spaces/tabs | |
content=`echo "$content" | sed '/^[[:blank:]]*$/d; /^#[^\!].*/d; s/^[[:space:]]\+//g; s/[[:space:]]\+$//g'` | |
# Forces one-line if-then, for-do, while-do, fi, done, ;; | |
content=`echo "$content" | sed ':a;N;$!ba;s/\nthen\n/\;then\n/g; s/\ndo\n/;do\n/g; s/\n;;/;;/g; s/\nfi\n/;fi\n/g; s/\ndone\n/;done\n/g'` | |
echo "$content" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment