module OSwitch::OS
Get OS
specific info. Like, what directories to mount in the container, current user, home directory, etc.
This module first defines methods common to Linux
and Darwin
, then does OS
detection and loads OS
specific code.
Public Class Methods
command?(command)
click to toggle source
Return `true` if the given command exists and is executable.
# File lib/oswitch/os.rb, line 11 def self.command?(command) system("which #{command} > /dev/null 2>&1") end
outputof(command)
click to toggle source
# File lib/oswitch/os.rb, line 15 def self.outputof(command) output = `#{command} 2> /dev/null`.chomp raise unless $CHILD_STATUS.success? output end
Public Instance Methods
cwd()
click to toggle source
# File lib/oswitch/os.rb, line 33 def cwd Dir.pwd end
home()
click to toggle source
# File lib/oswitch/os.rb, line 25 def home ENV['HOME'] end
shell()
click to toggle source
# File lib/oswitch/os.rb, line 29 def shell File.basename ENV['SHELL'] end
username()
click to toggle source
# File lib/oswitch/os.rb, line 21 def username ENV['USER'] end