1
0
mirror of https://github.com/meineerde/dotfiles.git synced 2025-10-17 19:41:01 +00:00
dotfiles/bin/json
2013-09-23 16:30:29 +02:00

29 lines
469 B
Ruby
Executable File

#!/usr/bin/env ruby
require 'rubygems' # 1.8.7
require 'json'
if STDIN.tty?
if File.exist?("/usr/bin/pbpaste")
data = IO.popen('/usr/bin/pbpaste', 'r+').read
else
$stderr.puts 'your_command | json [--color]'
exit 1
end
else
data = STDIN.read
end
begin
json = JSON.parse(data)
rescue JSON::ParserError => err
$stderr.puts err.message
exit 1
end
if ARGV.include?('--color')
require 'ap'
ap json
else
puts JSON.pretty_generate(json)
end