mirror of
https://github.com/meineerde/dotfiles.git
synced 2026-03-23 17:19:53 +00:00
Detect color options for json helper from environment
This commit is contained in:
parent
d978f53d53
commit
80ff4b6677
22
bin/json
22
bin/json
@ -3,6 +3,19 @@
|
|||||||
require 'rubygems' # 1.8.7
|
require 'rubygems' # 1.8.7
|
||||||
require 'json'
|
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 STDIN.tty?
|
||||||
if File.exist?("/usr/bin/pbpaste")
|
if File.exist?("/usr/bin/pbpaste")
|
||||||
data = IO.popen('/usr/bin/pbpaste', 'r+').read
|
data = IO.popen('/usr/bin/pbpaste', 'r+').read
|
||||||
@ -20,9 +33,6 @@ rescue JSON::ParserError => err
|
|||||||
$stderr.puts err.message
|
$stderr.puts err.message
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
if ARGV.include?('--color')
|
|
||||||
require 'ap'
|
colorize = !ARGV.include?('--no-color') && STDOUT.tty?
|
||||||
ap json
|
print_json(json, colorize)
|
||||||
else
|
|
||||||
puts JSON.pretty_generate(json)
|
|
||||||
end
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user