Sha256: 0e311d4e60bfc9957254a10fb95c19fe7572d72cff29d45ac56c56ebd28e1ce2

Contents?: true

Size: 1.09 KB

Versions: 14

Compression:

Stored size: 1.09 KB

Contents

require 'English'

class Thor
  module Actions
    # execute a shell command and raise an error if non-zero exit code is returned
    # return the string output from the command
    def run_cmd(cmd, options = {})
      say "$ #{cmd}"
      output = `#{cmd}`
      success = $CHILD_STATUS.to_i == 0
      fail "#{cmd} failed" unless success || options[:allow_failure]
      output
    end

    # launch configured editor to retreive message/string
    # see http://osdir.com/ml/ruby-talk/2010-06/msg01424.html
    # see https://gist.github.com/rkumar/456809
    # see http://rdoc.info/github/visionmedia/commander/master/Commander/UI.ask_editor
    def ask_editor(initial_text = '', editor = nil)
      editor ||= ENV['EDITOR'] || 'vi'
      Tempfile.open('comment.md') do |f|
        f << initial_text
        f.flush

        flags = case editor
        when 'mate', 'emacs', 'subl'
          '-w'
        when 'mvim'
          '-f'
        else
          ''
        end
        pid = fork { exec([editor, flags, f.path].join(' ')) }
        Process.waitpid(pid)
        File.read(f.path)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
thegarage-gitx-2.14.0 lib/thegarage/gitx/extensions/thor.rb
gitx-2.13.5.ci.46.1 lib/gitx/extensions/thor.rb
gitx-2.13.5 lib/gitx/extensions/thor.rb
gitx-2.13.4.ci.39.1 lib/gitx/extensions/thor.rb
gitx-2.13.4 lib/gitx/extensions/thor.rb
gitx-2.13.3 lib/gitx/extensions/thor.rb
gitx-2.13.2 lib/gitx/extensions/thor.rb
gitx-2.13.1 lib/gitx/extensions/thor.rb
thegarage-gitx-2.13.1 lib/thegarage/gitx/extensions/thor.rb
thegarage-gitx-2.13.0 lib/thegarage/gitx/extensions/thor.rb
thegarage-gitx-2.12.0 lib/thegarage/gitx/extensions/thor.rb
thegarage-gitx-2.11.0 lib/thegarage/gitx/extensions/thor.rb
thegarage-gitx-2.10.2 lib/thegarage/gitx/extensions/thor.rb
thegarage-gitx-2.10.1 lib/thegarage/gitx/extensions/thor.rb