mirror of
https://github.com/meineerde/dotfiles.git
synced 2025-10-17 19:41:01 +00:00
39 lines
654 B
Ruby
Executable File
39 lines
654 B
Ruby
Executable File
#!/usr/bin/env ruby
|
|
|
|
require 'rubygems' # 1.8.7
|
|
require 'json'
|
|
|
|
def print_json(json, colorize=true)
|
|
if colorize
|
|
begin
|
|
require 'awesome_print'
|
|
ap json
|
|
rescue LoadError
|
|
print_json(json, false)
|
|
end
|
|
else
|
|
puts JSON.pretty_generate(json)
|
|
end
|
|
end
|
|
|
|
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
|
|
|
|
colorize = ARGV.include?('--color')
|
|
print_json(json, colorize)
|