Module: Hackmac::Utils
- Includes:
- FileUtils
- Defined in:
- lib/hackmac/utils.rb
Overview
A module that provides utility methods for executing shell commands and interacting with users.
The Utils module includes methods for running system commands with colored output, prompting users for input, and handling common file operations in a Hackmac context.
Instance Method Summary collapse
-
#ask(prompt) ⇒ Boolean
The ask method prompts the user for a yes/no response.
-
#x(cmd, verbose: true) ⇒ String
The x method executes a shell command and displays its output with colorized prompts.
Instance Method Details
#ask(prompt) ⇒ Boolean
The ask method prompts the user for a yes/no response.
47 48 49 50 |
# File 'lib/hackmac/utils.rb', line 47 def ask(prompt) print prompt.bold.yellow gets =~ /\Ay/i end |
#x(cmd, verbose: true) ⇒ String
The x method executes a shell command and displays its output with colorized prompts.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/hackmac/utils.rb', line 27 def x(cmd, verbose: true) prompt = cmd =~ /\A\s*sudo/ ? ?# : ?$ cmd_output = "#{prompt} #{cmd}".color(27) + (verbose ? "" : " >/dev/null".yellow) output, result = nil, nil puts cmd_output system "#{cmd} 2>&1" result = $? if result.success? puts "✅ Command succeded!".green else puts "⚠️ Command #{cmd.inspect} failed with exit status #{result.exitstatus}".on_red.white exit result.exitstatus end output end |