Class: VundleCli::Uninstaller

Inherits:
Object
  • Object
show all
Defined in:
lib/vundle_cli/uninstaller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, bundle) ⇒ Uninstaller

Returns a new instance of Uninstaller.



18
19
20
21
22
23
24
# File 'lib/vundle_cli/uninstaller.rb', line 18

def initialize(options, bundle)
  @options = options
  @vimdir = Helpers.file_validate(options.vimdir, true)
  @settings_dir = Helpers.file_validate(options.settings, true)
  @vimrc = Helpers.file_validate(options.vimrc)
  @bundle = bundle
end

Instance Attribute Details

#bundleObject (readonly)

Returns the value of attribute bundle.



16
17
18
# File 'lib/vundle_cli/uninstaller.rb', line 16

def bundle
  @bundle
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/vundle_cli/uninstaller.rb', line 8

def options
  @options
end

#settings_dirObject (readonly)

Returns the value of attribute settings_dir.



12
13
14
# File 'lib/vundle_cli/uninstaller.rb', line 12

def settings_dir
  @settings_dir
end

#vimdirObject (readonly)

Returns the value of attribute vimdir.



10
11
12
# File 'lib/vundle_cli/uninstaller.rb', line 10

def vimdir
  @vimdir
end

#vimrcObject (readonly)

Returns the value of attribute vimrc.



14
15
16
# File 'lib/vundle_cli/uninstaller.rb', line 14

def vimrc
  @vimrc
end

Instance Method Details

#rmObject

1) Remove the line ‘Bundle bundle` from .vimrc. 2) Look for a file in the settings directory (provided by option –settings)

with name that includes the bundle name. Then ask if the user wants to remove it.


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/vundle_cli/uninstaller.rb', line 29

def rm
  tmp = Tempfile.new("vimrc_tmp")
  open(@vimrc, 'r').each { |l| 
    if l.chomp =~ /Bundle .*#{Regexp.quote(@bundle)}.*/
      puts "Found bundle #{@bundle}, removing it from #{@vimrc}..."
    else
      tmp << l
    end
  }
  tmp.close
  FileUtils.mv(tmp.path, @vimrc)

  puts "Searching for setting file..."

  # Get the bundle's main name.
  # (the provided @bundle usually looks like baopham/trailertrash.vim,
  # so we trim it down to get "trailertrash" only).
  bundle_name = @bundle
  if @bundle.include?("/")
    bundle_name = @bundle.split("/")[1].sub(/\.vim/, '')
  end

  Dir.foreach(@settings_dir) do |fname|
    next unless fname.downcase.include?(bundle_name.downcase)
    puts "Found #{@settings_dir}/#{fname} setting file. Remove it? (yes/no) "
    input = STDIN.gets.chomp
    if input == 'yes'
      File.delete("#{@settings_dir}/#{fname}")
      puts "File deleted."
    end
  end
end