Skip to content

Instantly share code, notes, and snippets.

@hron84
Created December 29, 2011 01:24
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 hron84/1530985 to your computer and use it in GitHub Desktop.
Save hron84/1530985 to your computer and use it in GitHub Desktop.
csspp

CSS Pretty Print

This script is formats css files even if they are compressed and/or minified.

It uses standard UNIX utilities to make its work:

  • POSIX sed
  • Perl (5.8 or later)
  • GNU gzip (if you want to uncompress gzipped CSS files, recommended)
  • BZip2 (if you want to uncompress CSS files compressed by BZip2, not needed)
  • XZ (f you want to uncompress CSS files compressed by XZ/LZMA, not needed)

Usage

The script supports to ways of usage. First is formatting a file:

csspp jquery.ui.jquery.ui.selectable.css

It converts this:

.ui-selectable-helper { position: absolute; z-index: 100; border:1px dotted black; }

To this:

.ui-selectable-helper  {
    position:  absolute;
    z-index:  100;
    border: 1px dotted black;
} 

The second usage is pipelining the source directly from internet:

curl -ks http://foobar.com/css/jquery.ui.selectable.css | csspp

The example is taken from jQuery UI 1.9.1

Installation

To install this script, simply clone this gist repo, and copy the file somewhere on your path. Do not forget adding executable bit to the file.

Known bugs/limitations

This script is not designed to be bullet-proof thus it does not check existence of used tools. It assumes you have installed tools, however, these tools are installed on a normal Unix/Linux desktop, so you do not need to do anything for prerequisites.

Licensing

This script is licensed under the terms of CreativeCommons Attribution-ShareAlike 3.0 license. To read the full license, visit its own homepage.

Copyright (C) 2011-2012 Gabor Garami. Some rights reserved.

#!/bin/sh
# This script is licensed under the terms of the Creative Commons BY-SA 3.0 license
# http://creativecommons.org/licenses/by-sa/3.0/
#
# Copyright (c) 2011 Gabor Garami. Some rights reserved
## This script reformats minified CSS files and fixes some formatting errors
filter='cat'
case $1 in
*.gz)
filter='gzip -dc'
;;
*.bz2)
filter='bzip2 -dc'
;;
*.xz)
filter='xz -dc'
;;
*)
filter='cat'
;;
esac
( [ -z "$1" ] && cat || $filter $1 ) | perl -pe 's/}/}\n\n/g;s/{/ {\n/g;s/\;/\;\n/g;s/:/: /g' | sed '/\;/s/^/ /g' | perl -pe 's/^\s+}/}/;s/^\s+(\S)/ \1/g'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment