Class: Sym::App::Commands::BashCompletion

Inherits:
BaseCommand show all
Defined in:
lib/sym/app/commands/bash_completion.rb

Constant Summary

Constants included from Sym

DESCRIPTION, VERSION

Instance Method Summary collapse

Methods included from Sym

config, default_key, default_key?, default_key_file

Constructor Details

This class inherits a constructor from Sym::App::Commands::BaseCommand

Instance Method Details

#executeObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sym/app/commands/bash_completion.rb', line 10

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