Last active
August 29, 2015 14:09
-
-
Save doloopwhile/8a2e742d98fbad227606 to your computer and use it in GitHub Desktop.
Pretify YAML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'yaml' | |
require 'pp' | |
ARGV.each do |a| | |
y = open(a) do |f| | |
YAML.load(f) | |
end | |
sort = lambda do |x| | |
if x.is_a? Hash | |
Hash[x.map{|k,v| [k, sort[v]]}.sort] | |
else | |
x | |
end | |
end | |
y = sort[y] | |
open(a, 'w') do |f| | |
y.to_yaml.lines.each do |line| | |
f.puts line.rstrip | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment