Instantly share code, notes, and snippets.

Embed
What would you like to do?
Watch your .pug and .jade files
#!/bin/bash
## Save this file into ~/bin and make it writeable (chmod +x pugwatch)
## Execute it from your project folder, e.g. ~/Sites
## It starts up very fast, takes no memory and will instantly compile any
## JADE / PUG files as soon as you create them.
## All dependencies will be installed automatically too.
## Created this because CodeKit (which I purchased) keeps hanging and crashing and being slow for a few years now
# Check for dependencies
which fswatch >/dev/null || brew install fswatch
which terminal-notifier >/dev/null || brew install terminal-notifier
which npm >/dev/null || brew install npm
which pug >/dev/null || npm install pug-cli -g
echo "Watching for .pug and .jade.."
fswatch -e '.*' -i '.jade$' -i '.pug$' . | while read x
do
pug "$x" \
&& terminal-notifier -group pug -title 'PUG Compiler' -subtitle 'Success' -message "$x" \
|| terminal-notifier -group pug -title 'PUG Compiler' -subtitle 'Failed' -message "$x" -sound Funk -action com.apple.Terminal
done
#Clicking on notification won't open terminal due to bug:
# https://github.com/julienXX/terminal-notifier/issues/180
@romaninsh

This comment has been minimized.

Owner

romaninsh commented May 17, 2018

I have improved the script by also compiling less files:

#!/bin/bash

# Check for dependencies
which fswatch >/dev/null || brew install fswatch
which terminal-notifier >/dev/null || brew install terminal-notifier
which npm >/dev/null || brew install npm
which pug >/dev/null || npm install pug-cli -g

echo "Watching for .less, .pug and .jade.."

fswatch -e '.*' -i '.jade$' -i '.pug$' -i '.less$' . | while read x
do
    if echo $x | grep 'less$'; then
        lessc $x > `echo $x | sed 's/less$/css/'` \
            && terminal-notifier -group pug -title 'LESS Compiler' -subtitle 'Success' -message "$x" \
            || terminal-notifier -group pug -title 'LESS Compiler' -subtitle 'Failed' -message "$x" -sound Funk -action com.apple.Terminal

        continue
    fi
    pug -P "$x" \
        && terminal-notifier -group pug -title 'PUG Compiler' -subtitle 'Success' -message "$x" \
        || terminal-notifier -group pug -title 'PUG Compiler' -subtitle 'Failed' -message "$x" -sound Funk -action com.apple.Terminal
done

#Clicking on notification won't open terminal due to bug:
# https://github.com/julienXX/terminal-notifier/issues/180
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment