Sha256: adafec3b2fce8c3340bd424742569c8665937d8a484b379e284ce16e13a56096

Contents?: true

Size: 1.45 KB

Versions: 314

Compression:

Stored size: 1.45 KB

Contents

require 'travis/tools/assets'
require 'travis/cli'
require 'fileutils'
require 'erb'

module Travis
  module Tools
    module Completion
      RCS = ['.zshrc', '.bashrc'].map { |f| File.expand_path(f, ENV['HOME']) }
      include FileUtils
      extend self

      def config_path
        ENV.fetch('TRAVIS_CONFIG_PATH') { File.expand_path('.travis', ENV['HOME']) }
      end

      def cmp_file
        File.expand_path('travis.sh', config_path)
      end

      def install_completion
        update_completion
        source = "source " << cmp_file

        RCS.each do |file|
          next unless File.exist? file and File.writable? file
          next if File.read(file).include? source
          File.open(file, "a") { |f| f.puts("", "# added by travis gem", "[ -f #{cmp_file} ] && #{source}") }
        end
      end

      def update_completion
        mkdir_p(config_path)
        cp(Assets['travis.sh'], cmp_file)
      end

      def completion_installed?
        source = "source " << config_path
        RCS.each do |file|
          next unless File.exist? file and File.writable? file
          return false unless File.read(file).include? source
        end
        true
      end

      def compile
        commands = Travis::CLI.commands.sort_by { |c| c.command_name }
        template = Assets.read('travis.sh.erb')
        source   = ERB.new(template).result(binding).gsub(/^ +\n/, '')
        File.write(Assets['travis.sh'], source)
      end
    end
  end
end

Version data entries

314 entries across 314 versions & 3 rubygems

Version Path
travis-1.8.11.travis.1025.11 lib/travis/tools/completion.rb
travis-1.8.11.travis.1024.11 lib/travis/tools/completion.rb
travis-1.8.11.travis.1022.11 lib/travis/tools/completion.rb
travis-1.8.11.travis.1021.11 lib/travis/tools/completion.rb
travis-1.8.11.travis.1020.11 lib/travis/tools/completion.rb
travis-1.8.11.travis.1012.9 lib/travis/tools/completion.rb
travis-1.8.11.travis.1011.9 lib/travis/tools/completion.rb
travis-1.8.11.travis.1010.9 lib/travis/tools/completion.rb
travis-1.8.11.travis.1009.9 lib/travis/tools/completion.rb
travis-1.8.11.travis.1008.9 lib/travis/tools/completion.rb
travis-1.8.11.travis.1007.9 lib/travis/tools/completion.rb
travis-1.8.11.travis.1004.9 lib/travis/tools/completion.rb
travis-1.8.11.travis.1003.9 lib/travis/tools/completion.rb
travis-1.8.11.travis.1002.9 lib/travis/tools/completion.rb
travis-1.8.11.travis.1001.9 lib/travis/tools/completion.rb
travis-1.8.11.travis.1000.9 lib/travis/tools/completion.rb
travis-1.8.11.travis.998.9 lib/travis/tools/completion.rb
travis-1.8.10.travis.997.9 lib/travis/tools/completion.rb
travis-1.8.10 lib/travis/tools/completion.rb
travis-1.8.10.travis.994.9 lib/travis/tools/completion.rb