lib/boom/platform.rb in boom-0.3.0 vs lib/boom/platform.rb in boom-0.4.0
- old
+ new
@@ -12,20 +12,20 @@
class << self
# Public: tests if currently running on darwin.
#
# Returns true if running on darwin (MacOS X), else false
def darwin?
- !!(RUBY_PLATFORM =~ /darwin/)
+ !!(RbConfig::CONFIG['host_os'] =~ /darwin/)
end
# Public: tests if currently running on windows.
#
# Apparently Windows RUBY_PLATFORM can be 'win32' or 'mingw32'
#
# Returns true if running on windows (win32/mingw32), else false
def windows?
- !!(RUBY_PLATFORM =~ /mswin|mingw/)
+ !!(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/)
end
# Public: returns the command used to open a file or URL
# for the current platform.
#
@@ -33,11 +33,11 @@
#
# Returns a String with the bin
def open_command
if darwin?
'open'
- elsif windows?
+ elsif windows?
'start'
else
'xdg-open'
end
end
@@ -67,27 +67,33 @@
'clip'
else
'xclip -selection clipboard'
end
end
-
+
# Public: copies a given Item's value to the clipboard. This method is
# designed to handle multiple platforms.
#
# Returns the String value of the Item.
def copy(item)
- IO.popen(copy_command,"w") {|cc| cc.write(item.value)}
- item.value
+ begin
+ IO.popen(copy_command,"w") {|cc| cc.write(item.value)}
+ item.value
+ rescue Errno::ENOENT
+ puts item.value
+ puts "Please install #{copy_command[0..5]} to copy this item to your clipboard"
+ exit
+ end
end
# Public: opens the JSON file in an editor for you to edit. Uses the
# $EDITOR environment variable, or %EDITOR% on Windows for editing.
# This method is designed to handle multiple platforms.
# If $EDITOR is nil, try to open using the open_command.
#
# Returns a String with a helpful message.
def edit(json_file)
- unless $EDITOR.nil?
+ unless ENV['EDITOR'].nil?
unless windows?
system("`echo $EDITOR` #{json_file} &")
else
system("start %EDITOR% #{json_file}")
end