diff options
author | katherine <shmibs@shmibbles.me> | 2018-10-05 06:34:11 -0700 |
---|---|---|
committer | katherine <shmibs@shmibbles.me> | 2018-10-05 06:34:11 -0700 |
commit | d3e04cf4b6b0b3898698d7eadd250bea20e3b292 (patch) | |
tree | 11a5359420cbd1bc7c8ea912999dd3f13cb7e067 /.config/init | |
parent | 08024e9a5df285e74577d7228d2d33a504bcb023 (diff) | |
download | dotfiles-d3e04cf4b6b0b3898698d7eadd250bea20e3b292.tar.gz |
add coffee compiling script
it's messy, but it works. tools aren't the best ┐('~`;)┌
Diffstat (limited to '.config/init')
-rw-r--r-- | .config/init/funcreqs/cofe | 2 | ||||
-rwxr-xr-x | .config/init/funcs/cofe | 43 |
2 files changed, 45 insertions, 0 deletions
diff --git a/.config/init/funcreqs/cofe b/.config/init/funcreqs/cofe new file mode 100644 index 0000000..a42abf4 --- /dev/null +++ b/.config/init/funcreqs/cofe @@ -0,0 +1,2 @@ +func_init_prereqs=(coffee babel) +func_init_checks=() diff --git a/.config/init/funcs/cofe b/.config/init/funcs/cofe new file mode 100755 index 0000000..509e24b --- /dev/null +++ b/.config/init/funcs/cofe @@ -0,0 +1,43 @@ +#!/usr/bin/env zsh +# compile coffeescript. sorry about the mess x-x + +local strval +local rval +rval=0 + +[[ $#@ -lt 1 ]] \ + && echo "\e[1;31merr:\e[0m please specify one or more files to compile" \ + && return 1 + +for f in $@; do + echo -n "\e[1m[${f}]...\e[0m" + + # check if file is readable + if [[ ! -r $f || ! -f $f ]] then + echo " \e[1;31mx\e[0m" \ + && >&2 echo "err: file could not be read" + continue + fi + + # check if containing dir and outfile are writeable + if [[ ! -w ${f:h} || ! -w ${f} ]] then + echo " \e[1;31mx\e[0m" \ + && >&2 echo "err: could not write to file" + continue + fi + + # try compile + (cat $f | coffee -sc | babel --minified --no-babelrc --no-comments \ + | tr -d '\n' > ${f:r}.js) 2>&1 \ + | read -r -d "\0" strval + + # err check + [[ $strval ]] \ + && echo " \e[1;31mx\e[0m" \ + && >&2 (echo $strval | sed 's/^\[stdin\]://') \ + && rval=1 && rm ${f:r}.js && continue + + echo " \e[1;32mo\e[0m" +done + +return $rval |