Skip to content

Instantly share code, notes, and snippets.

@romaninsh
Created December 22, 2016 16:54
Show Gist options
  • Save romaninsh/e6c783ec916ae176f55e3ee6b5e43b73 to your computer and use it in GitHub Desktop.
Save romaninsh/e6c783ec916ae176f55e3ee6b5e43b73 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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