Sha256: b1feb1fd51bb84fbccb1a5e5f211770637e4e67b7fd52d5b244f90f8ae84a81e

Contents?: true

Size: 1.09 KB

Versions: 9

Compression:

Stored size: 1.09 KB

Contents

require 'canals'
require 'canals/tools/assets'

module Canals
  module Tools
    module Completion
      include FileUtils
      extend self

      def config_path
        File.expand_path(".canals", ENV['HOME'])
      end

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

      def install_completion
        update_completion
        source = "source " << cmp_file

        rcfile = File.expand_path('.bashrc', ENV['HOME'])
        return if File.read(rcfile).include? source
        File.open(rcfile, 'a') { |f| f.puts("", "# added by canals gem", "[ -f #{cmp_file} ] && #{source}") }
      end

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

      def update_config
        Canals.config[:completion_version] = Canals::VERSION
        Canals.config.save!
      end

      def completion_installed?
        source = "source " << cmp_file
        rcfile = File.expand_path('.bashrc', ENV['HOME'])
        return false unless File.read(rcfile).include? source
        true
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
canals-0.9.0 lib/canals/tools/completion.rb
canals-0.8.7 lib/canals/tools/completion.rb
canals-0.8.6 lib/canals/tools/completion.rb
canals-0.8.5 lib/canals/tools/completion.rb
canals-0.8.4 lib/canals/tools/completion.rb
canals-0.8.3 lib/canals/tools/completion.rb
canals-0.8.2 lib/canals/tools/completion.rb
canals-0.8.1 lib/canals/tools/completion.rb
canals-0.8.0 lib/canals/tools/completion.rb