lib/howzit/task.rb in howzit-2.0.20 vs lib/howzit/task.rb in howzit-2.0.21

- old
+ new

@@ -92,69 +92,14 @@ ## Execute a copy task ## def run_copy title = Howzit.options[:show_all_code] ? @action : @title Howzit.console.info("{bg}Copied {bw}#{title}{bg} to clipboard{x}".c) - os_copy(@action) + Util.os_copy(@action) end ## - ## Platform-agnostic copy-to-clipboard - ## - ## @param string [String] The string to copy - ## - def os_copy(string) - os = RbConfig::CONFIG['target_os'] - out = "{bg}Copying {bw}#{string}".c - case os - when /darwin.*/i - Howzit.console.debug("#{out} (macOS){x}".c) - `echo #{Shellwords.escape(string)}'\\c'|pbcopy` - when /mingw|mswin/i - Howzit.console.debug("#{out} (Windows){x}".c) - `echo #{Shellwords.escape(string)} | clip` - else - if 'xsel'.available? - Howzit.console.debug("#{out} (Linux, xsel){x}".c) - `echo #{Shellwords.escape(string)}'\\c'|xsel -i` - elsif 'xclip'.available? - Howzit.console.debug("#{out} (Linux, xclip){x}".c) - `echo #{Shellwords.escape(string)}'\\c'|xclip -i` - else - Howzit.console.debug(out) - Howzit.console.warn('Unable to determine executable for clipboard.') - end - end - end - - ## - ## Platform-agnostic open command - ## - ## @param command [String] The command - ## - def os_open(command) - os = RbConfig::CONFIG['target_os'] - out = "{bg}Opening {bw}#{command}".c - case os - when /darwin.*/i - Howzit.console.debug "#{out} (macOS){x}".c if Howzit.options[:log_level] < 2 - `open #{Shellwords.escape(command)}` - when /mingw|mswin/i - Howzit.console.debug "#{out} (Windows){x}".c if Howzit.options[:log_level] < 2 - `start #{Shellwords.escape(command)}` - else - if 'xdg-open'.available? - Howzit.console.debug "#{out} (Linux){x}".c if Howzit.options[:log_level] < 2 - `xdg-open #{Shellwords.escape(command)}` - else - Howzit.console.debug out if Howzit.options[:log_level] < 2 - Howzit.console.debug 'Unable to determine executable for `open`.' - end - end - end - - ## ## Execute the task ## def run output = [] tasks = 1 @@ -167,10 +112,10 @@ when :run run_run when :copy run_copy when :open - os_open(@action) + Util.os_open(@action) end end [output, tasks] end