Class: PGit::Installer::BashAutoCompletion

Inherits:
Object
  • Object
show all
Defined in:
lib/pgit/installer/bash_auto_completion.rb

Constant Summary collapse

FILENAME =
"~/.pgit_auto_completion"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(global_opts, opts, args) ⇒ BashAutoCompletion

Returns a new instance of BashAutoCompletion.



22
23
# File 'lib/pgit/installer/bash_auto_completion.rb', line 22

def initialize(global_opts, opts, args)
end

Class Method Details

.scriptObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/pgit/installer/bash_auto_completion.rb', line 6

def self.script
  autocompletion = <<-AUTOCOMPLETION
    function get_pgit_commands
    {
      if [ -z $2 ]; then
        COMPREPLY=(`pgit help -c`)
      else
        COMPREPLY=(`pgit help -c $2`)
      fi
    }
    complete -F get_pgit_commands pgit
  AUTOCOMPLETION

  PGit::Helpers::Heredoc.remove_front_spaces(autocompletion)
end

Instance Method Details

#source_completer_from_bashrcObject



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/pgit/installer/bash_auto_completion.rb', line 34

def source_completer_from_bashrc
  if already_sourced?
    puts "Already sourcing #{FILENAME} in ~/.bashrc"
  else
    bashrc_expanded_path = File.expand_path("~/.bashrc")
    b = File.open(bashrc_expanded_path, 'a')
    b.puts "source #{FILENAME}"
    b.close

    puts "~/.bashrc will now source #{FILENAME}"
  end
end

#write_completer_fileObject



25
26
27
28
29
30
31
32
# File 'lib/pgit/installer/bash_auto_completion.rb', line 25

def write_completer_file
  expanded_path = File.expand_path(FILENAME)
  f = File.open(expanded_path, 'w')
  f.puts PGit::Installer::BashAutoCompletion.script
  f.close

  puts "Wrote autocompletion script under #{FILENAME}"
end