Skip to content

Instantly share code, notes, and snippets.

@sheepeeh
Created June 20, 2014 14:58
Show Gist options
  • Save sheepeeh/39c25bd67ccc09ad78a0 to your computer and use it in GitHub Desktop.
Save sheepeeh/39c25bd67ccc09ad78a0 to your computer and use it in GitHub Desktop.
Get the current working directory (used for many of my little command line utilities.)
require 'rbconfig'
def init
@os
@current_dir
end
def os
@os ||= (
host_os = RbConfig::CONFIG['host_os']
case host_os
when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
:windows
when /darwin|mac os/
:macosx
when /linux/
:linux
when /solaris|bsd/
:unix
else
raise Error::WebDriverError, "unknown os: #{host_os.inspect}"
end
)
end
def current_dir
os
if os == :windows
@current_dir = %x(chdir)
@current_dir = @current_dir.gsub("\\","/")
@current_dir = @current_dir.gsub("\n","")
else
@current_dir = %x(pwd)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment