mirror of
https://github.com/meineerde/dotfiles.git
synced 2026-02-06 00:53:23 +00:00
Pretty print JSON
This commit is contained in:
parent
644772b6e7
commit
e664bba35e
23
bin/json
Executable file
23
bin/json
Executable file
@ -0,0 +1,23 @@
|
||||
#!/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
|
||||
|
||||
json = JSON.parse(data)
|
||||
if ARGV.include?('--color')
|
||||
require 'ap'
|
||||
ap json
|
||||
else
|
||||
puts JSON.pretty_generate(json)
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user