Skip to content

Instantly share code, notes, and snippets.

@Kimtaro
Created March 12, 2009 05:48
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 Kimtaro/77928 to your computer and use it in GitHub Desktop.
Save Kimtaro/77928 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# TextMate command for very simple pretty-printing of SQL
print $stdin.readlines.join("\n").gsub(/
(
SELECT (\s+ DISTINCT)? |
FROM |
(LEFT (\s+ OUTER)? | INNER)? \s* JOIN |
UNION |
WHERE |
GROUP \s+ BY |
ORDER \s+ BY |
LIMIT
) \s*/x, "\n" + '\1' + "\n\t")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment