Skip to content

Instantly share code, notes, and snippets.

@ddrscott
Last active February 2, 2017 10:30
Show Gist options
  • Save ddrscott/f2dfe6576558eee7c160d1093930012d to your computer and use it in GitHub Desktop.
Save ddrscott/f2dfe6576558eee7c160d1093930012d to your computer and use it in GitHub Desktop.
SQL pretty print using ruby and python
#!/usr/bin/env ruby
require 'coderay'
require 'open3'
# # Dependencies
# `coderay` is a ruby gem.
# Install it with:
# ```
# $ gem install coderay
# ```
#
# `sqlformat` is a python program
# make sure it's installed and available in your path.
# ```
# $ pip install --upgrade sqlparse
# $ export PATH=$PATH:~/Library/Python/3.5/bin
# ```
sql = ARGF.read
out, _status = Open3.capture2('sqlformat -k upper -i lower --reindent_aligned -', :stdin_data=>sql)
puts CodeRay.scan(out, :sql).terminal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment