Module: Canals::Tools::Completion

Extended by:
Completion
Includes:
FileUtils
Included in:
Completion
Defined in:
lib/canals/tools/completion.rb

Instance Method Summary collapse

Instance Method Details

#cmp_fileObject



15
16
17
# File 'lib/canals/tools/completion.rb', line 15

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

#completion_installed?Boolean

Returns:

  • (Boolean)


40
41
42
43
44
45
# File 'lib/canals/tools/completion.rb', line 40

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

#config_pathObject



11
12
13
# File 'lib/canals/tools/completion.rb', line 11

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

#install_completionObject



19
20
21
22
23
24
25
26
27
# File 'lib/canals/tools/completion.rb', line 19

def install_completion
  update_completion
  source = "source " << cmp_file

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

#update_completionObject



29
30
31
32
33
# File 'lib/canals/tools/completion.rb', line 29

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

#update_configObject



35
36
37
38
# File 'lib/canals/tools/completion.rb', line 35

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