Sha256: 99ba7eb1d0a002b99b4b0a9188f329a08770155fa29643162df1600e6321f9db

Contents?: true

Size: 1.57 KB

Versions: 23

Compression:

Stored size: 1.57 KB

Contents

module Timber
  class CLI
    module OSHelper
      def self.can_copy_to_clipboard?
        `which pbcopy` != ""
      rescue Exception
        false
      end

      def self.copy_to_clipboard(input)
        ::IO.popen('pbcopy', 'w') { |f| f << input }
        true
      rescue Exception
        false
      end

      def self.git_clean_working_tree?
        `git diff-index --quiet HEAD -- || echo "untracked";` == ""
      end

      def self.git_commit_changes
        begin
          `git add config/initializers/timber.rb`
        rescue Exception
        end

        `git commit -am 'Install the timber logger'`
        true
      rescue Exception
        false
      end

      def self.git_master?
        `git rev-parse --abbrev-ref HEAD` == "master"
      end

      def self.has_git?
        begin
          `which git` != ""
        rescue Exception
          false
        end
      end

      def self.can_open?
        begin
          `which #{open_command}` != ""
        rescue Exception
          false
        end
      end

      # Attemps to open a URL in the user's default browser across
      # the popular operating systems.
      def self.open(link)
        `#{open_command} #{link}`
        true
      rescue Exception
        false
      end

      private
        def self.open_command
          if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
            "start"
          elsif RbConfig::CONFIG['host_os'] =~ /darwin/
            "open"
          elsif RbConfig::CONFIG['host_os'] =~ /linux|bsd/
            "xdg-open"
          end
        end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
timber-2.1.7 lib/timber/cli/os_helper.rb
timber-2.1.6 lib/timber/cli/os_helper.rb
timber-2.1.5 lib/timber/cli/os_helper.rb