Skip to content

Instantly share code, notes, and snippets.

@fernandoaleman
Created October 16, 2011 04:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fernandoaleman/1290505 to your computer and use it in GitHub Desktop.
Save fernandoaleman/1290505 to your computer and use it in GitHub Desktop.
Show Mac OS Version
#!/usr/bin/ruby
module Tty extend self
def blue; bold 34; end
def white; bold 39; end
def red; underline 31; end
def reset; escape 0; end
def bold n; escape "1;#{n}" end
def underline n; escape "4;#{n}" end
def escape n; "\033[#{n}m" if STDOUT.tty? end
end
class Array
def shell_s
cp = dup
first = cp.shift
cp.map{ |arg| arg.gsub " ", "\\ " }.unshift(first) * " "
end
end
def ohai *args
puts "#{Tty.blue}==>#{Tty.white} #{args.shell_s}#{Tty.reset}"
end
def macos_version
@macos_version ||= /(10\.\d+)(\.\d+)?/.match(`/usr/bin/sw_vers -productVersion`).captures.first.to_f
end
ohai macos_version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment