lib/sct/config.rb in sct-0.1.7 vs lib/sct/config.rb in sct-0.1.8

- old
+ new

@@ -6,11 +6,11 @@ UBUNTU = "Ubuntu" def self.dir user = ENV["SUDO_USER"] || ENV["USER"] - if `uname -a`.match?("Darwin") + if self.operatingSystem == MAC_OS home = "/Users" else home = "/home" end @@ -56,8 +56,36 @@ else os = UBUNTU end return os + end + + ### + # Get the actual home path of the user. This may be different depending on the operating system + ### + def self.getTrueHomePath + home_path = `echo ~` + if self.operatingSystem == WINDOWS + home_path = self.convertWindowsToWSLPath(`cmd.exe /c echo %userprofile%`) + end + + return home_path + end + + def self.convertWindowsToWSLPath(path) + if self.operatingSystem == WINDOWS + return path.gsub(/C:\\/, '/mnt/c/').gsub(/\\\\/, "/").gsub(/\\/, '/').gsub(/\r\n?/, '') + end + + return path + end + + def self.convertWSLToWindowsPath(path) + if self.operatingSystem == WINDOWS + return path.gsub(/\/mnt\/c/, 'C:/').gsub(/\/\//, '/').gsub(/\\\\/, "/").gsub(/\r\n?/, '') + end + + return path end end end