Sha256: 0923adef617d0e2bcbc3648f4a1e41f7ecbc0ff5450403a91759715609286b47

Contents?: true

Size: 771 Bytes

Versions: 3

Compression:

Stored size: 771 Bytes

Contents

require 'term/ansicolor'
class String
  include Term::ANSIColor
end
require 'tabulo'
require 'fileutils'
require 'tmpdir'
require 'find'

module Hackmac
  module Utils
    include FileUtils

    def x(cmd, verbose: true)
      prompt = cmd =~ /\A\s*sudo/ ? ?# : ?$
      output = `#{cmd}`
      if $?.success?
        print "#{prompt} #{cmd}".green
        puts verbose ? "" : " >/dev/null".yellow
      else
        print "#{prompt} #{cmd}".red
        puts verbose ? "" : " >/dev/null".yellow
        STDERR.puts "command #{cmd.inspect} failed with exit status #{$?.exitstatus}".on_red.white
      end
      if verbose
        print output.italic
      end
      output
    end

    def ask(prompt)
      print prompt.bold.yellow
      gets =~ /\Ay/i
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hackmac-0.4.0 lib/hackmac/utils.rb
hackmac-0.3.4 lib/hackmac/utils.rb
hackmac-0.3.3 lib/hackmac/utils.rb