lib/helper.rb in narou-1.5.1 vs lib/helper.rb in narou-1.5.2
- old
+ new
@@ -12,21 +12,27 @@
#
module Helper
extend self
def os_windows?
- @@os_is_windows ||= RUBY_PLATFORM =~ /mswin(?!ce)|mingw|cygwin|bccwin/i
+ @@os_is_windows ||= RUBY_PLATFORM =~ /mswin(?!ce)|mingw|bccwin/i
end
+ def os_cygwin?
+ @@os_is_cygwin ||= RUBY_PLATFORM =~ /cygwin/i
+ end
+
def os_mac?
@@os_is_mac ||= RUBY_PLATFORM =~ /darwin/
end
def determine_os
case
when os_windows?
:windows
+ when os_cygwin?
+ :cygwin
when os_mac?
:mac
else
:other
end
@@ -60,10 +66,12 @@
return unless confirm(confirm_message)
end
case determine_os
when :windows
`explorer "file:///#{path.encode(Encoding::Windows_31J)}"`
+ when :cygwin
+ `cygstart "#{path}"`
when :mac
`open "#{path}"`
else
open_browser_linux(path, "フォルダが開けませんでした")
end
@@ -73,10 +81,12 @@
case determine_os
when :windows
escaped_url = url.gsub("%", "%^").gsub("&", "^&")
# MEMO: start の引数を "" で囲むと動かない
`start #{escaped_url}`
+ when :cygwin
+ `cygstart #{url}`
when :mac
`open "#{url}"`
else
open_browser_linux(url, "ブラウザが見つかりませんでした")
end
@@ -111,9 +121,16 @@
result = str.encode("UTF-16BE", "UTF-8", :invalid => :replace, :undef => :replace, :replace => "?").encode("UTF-8")
ENTITIES.each do |key, value|
result.gsub!("&#{key};", value)
end
result
+ end
+
+ #
+ # CYGWINのパスからwindowsのパスへと変換(cygpathを呼び出すだけ)
+ #
+ def convert_to_windows_path(path)
+ `cygpath -aw \"#{path}\"`.strip
end
#
# 外部コマンド実行中の待機ループの処理を書けるクラス
#