Sha256: 64a3a4bf86a466fcdc52d2e0ac48fe7a4250050adee675fcf40bbdaf27a2c28b

Contents?: true

Size: 1.22 KB

Versions: 32

Compression:

Stored size: 1.22 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, footer: nil)
      editor ||= ENV['EDITOR'] || 'vi'
      initial_text += "\n\n#{footer}" if footer
      text = Tempfile.open('text.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
      text = text.gsub(footer, '') if footer
      text.chomp.strip
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
gitx-2.21.1.ci.125.1 lib/gitx/extensions/thor.rb
gitx-2.21.1 lib/gitx/extensions/thor.rb
gitx-2.21.0.ci.121.1 lib/gitx/extensions/thor.rb
gitx-2.21.0 lib/gitx/extensions/thor.rb
gitx-2.20.0 lib/gitx/extensions/thor.rb
gitx-2.20.0.ci.117.1 lib/gitx/extensions/thor.rb
gitx-2.19.0.ci.114.1 lib/gitx/extensions/thor.rb
gitx-2.19.0.ci.112.1 lib/gitx/extensions/thor.rb
gitx-2.19.0 lib/gitx/extensions/thor.rb
gitx-2.18.0.ci.106.1 lib/gitx/extensions/thor.rb
gitx-2.18.0 lib/gitx/extensions/thor.rb
gitx-2.18.0.pre.ci.104.1 lib/gitx/extensions/thor.rb
gitx-2.18.0.pre lib/gitx/extensions/thor.rb
gitx-2.17.0.pre.ci.101.1 lib/gitx/extensions/thor.rb
gitx-2.17.0.pre lib/gitx/extensions/thor.rb
gitx-2.17.0.pre.ci.98.1 lib/gitx/extensions/thor.rb
gitx-2.16.0.ci.91.1 lib/gitx/extensions/thor.rb
gitx-2.16.0 lib/gitx/extensions/thor.rb
gitx-2.16.0.ci.89.1 lib/gitx/extensions/thor.rb
gitx-2.16.0.pre.ci.88.1 lib/gitx/extensions/thor.rb