Created
June 20, 2014 14:58
-
-
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.)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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