Skip to content

Instantly share code, notes, and snippets.

@vbarbarosh
Last active June 14, 2019 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vbarbarosh/70a9afd82cf9864753e7e27cabfea285 to your computer and use it in GitHub Desktop.
Save vbarbarosh/70a9afd82cf9864753e7e27cabfea285 to your computer and use it in GitHub Desktop.
css_pretty_format – How to pretty print css https://codescreens.com
#!/bin/bash
# http://www.gnu.org/software/bash/manual/bash.html#The-Set-Builtin
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -o nounset -o errexit -o pipefail
# How to pretty print css
#
# usage
# $ cat a.css | ./css_pretty_format > out.css
#
# before begin
# $ npm install -g cssbeautify-cli
# cssbeautify-cli will preserve all of the \n at the end of source
# file. This is why a small preprocessing is necessary. At first one
# \n is added to the end. Then all of \n but one will be removed from
# the end.
# http://sed.sourceforge.net/sed1line.txt
(cat; echo) | sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' | cssbeautify-cli -s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment