Sha256: c32aa8a1fd77c56018dfa0cd091ec71e28cfed4a3a834d5bc1fe442fad1f53ad

Contents?: true

Size: 1.48 KB

Versions: 7

Compression:

Stored size: 1.48 KB

Contents

require 'sym/app/commands/base_command'
module Sym
  module App
    module Commands
      class BashCompletion < BaseCommand

        required_options [:bash_support]
        try_after :generate_key, :open_editor, :encrypt, :decrypt

        def execute
          file = opts[:bash_support]

          out = ''
          Sym::Constants::Bash::Config.each_pair do |key, config|
            script_name = key.to_s
            FileUtils.cp(config[:source], config[:dest])
            out << if File.exist?(file)
                     if File.read(file).include?(config[:script])
                       "#{'OK'.bold.green}, #{file.bold.yellow} already has #{script_name.bold.blue} installed\n"
                     else
                       append_completion_script(file, config[:script])
                       "#{'OK'.bold.green}, appended initialization for #{script_name.bold.blue} to #{file.bold.yellow}\n"
                     end
                   else
                     append_completion_script(file, config[:script])
                     "#{'OK'.bold.green}, created new file #{file.bold.yellow}, added #{script_name.bold.blue} initialization.\n"
                   end
          end
          out + "Please reload your terminal session to activate bash completion and other installed utilities.\n"
        end

        private

        def append_completion_script(file, script)
          File.open(file, 'a') do |fd|
            fd.write(script + "\n")
          end
        end

      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sym-2.7.0 lib/sym/app/commands/bash_completion.rb
sym-2.6.3 lib/sym/app/commands/bash_completion.rb
sym-2.6.2 lib/sym/app/commands/bash_completion.rb
sym-2.6.1 lib/sym/app/commands/bash_completion.rb
sym-2.6.0 lib/sym/app/commands/bash_completion.rb
sym-2.5.3 lib/sym/app/commands/bash_completion.rb
sym-2.5.1 lib/sym/app/commands/bash_completion.rb