Class: VundleCli::Uninstaller
- Inherits:
-
Object
- Object
- VundleCli::Uninstaller
- Defined in:
- lib/vundle_cli/uninstaller.rb
Instance Attribute Summary collapse
-
#force ⇒ Object
readonly
Returns the value of attribute force.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#plugin ⇒ Object
readonly
Returns the value of attribute plugin.
-
#settings_dir ⇒ Object
readonly
Returns the value of attribute settings_dir.
-
#vimdir ⇒ Object
readonly
Returns the value of attribute vimdir.
-
#vimrc ⇒ Object
readonly
Returns the value of attribute vimrc.
Instance Method Summary collapse
- #ambiguous?(plugin) ⇒ Boolean
- #delete_plugin_dir(plugin_name) ⇒ Object
- #delete_setting_file(plugin_name) ⇒ Object
-
#initialize(options, plugin = nil) ⇒ Uninstaller
constructor
A new instance of Uninstaller.
-
#rm(modify_vimrc = true) ⇒ Object
1) Remove the line ‘Bundle plugin_name` or `Plugin plugin_name` from .vimrc.
Constructor Details
#initialize(options, plugin = nil) ⇒ Uninstaller
Returns a new instance of Uninstaller.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/vundle_cli/uninstaller.rb', line 10 def initialize(, plugin = nil) @options = @vimdir = file_validate(.vimdir, true) @settings_dir = file_validate(.settings, true) @vimrc = file_validate(.vimrc) @force = .force unless plugin.nil? @plugin = plugin abort("Plugin name too ambiguous.") if ambiguous?(plugin) end end |
Instance Attribute Details
#force ⇒ Object (readonly)
Returns the value of attribute force.
8 9 10 |
# File 'lib/vundle_cli/uninstaller.rb', line 8 def force @force end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/vundle_cli/uninstaller.rb', line 8 def @options end |
#plugin ⇒ Object (readonly)
Returns the value of attribute plugin.
8 9 10 |
# File 'lib/vundle_cli/uninstaller.rb', line 8 def plugin @plugin end |
#settings_dir ⇒ Object (readonly)
Returns the value of attribute settings_dir.
8 9 10 |
# File 'lib/vundle_cli/uninstaller.rb', line 8 def settings_dir @settings_dir end |
#vimdir ⇒ Object (readonly)
Returns the value of attribute vimdir.
8 9 10 |
# File 'lib/vundle_cli/uninstaller.rb', line 8 def vimdir @vimdir end |
#vimrc ⇒ Object (readonly)
Returns the value of attribute vimrc.
8 9 10 |
# File 'lib/vundle_cli/uninstaller.rb', line 8 def vimrc @vimrc end |
Instance Method Details
#ambiguous?(plugin) ⇒ Boolean
22 23 24 25 |
# File 'lib/vundle_cli/uninstaller.rb', line 22 def ambiguous?(plugin) plugin_name = plugin_base_name(plugin) plugin_trim_name(plugin_name).empty? end |
#delete_plugin_dir(plugin_name) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/vundle_cli/uninstaller.rb', line 80 def delete_plugin_dir(plugin_name) plugin_dir = "#{@vimdir}/bundle/#{plugin_name}" dirs = # If the user uses the exact name of the plugin, remove it. if Dir.exists?(plugin_dir) [plugin_dir] # else, search for plugin folders with substring plugin_name. else Dir["#{@vimdir}/bundle/*#{plugin_name}*"] end dirs.each { |b| yes = true unless @force yes = agree? "Found #{b}. Remove it? (y/n) ", :yellow end if yes FileUtils.rm_rf(b) say_ok "---#{b} deleted---" end } end |
#delete_setting_file(plugin_name) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/vundle_cli/uninstaller.rb', line 64 def delete_setting_file(plugin_name) trimmed_name = plugin_trim_name(plugin_name) Dir.foreach(@settings_dir) do |fname| next if fname == '.' or fname == '..' next unless fname.downcase.include?(trimmed_name.downcase) yes = true unless @force yes = agree? "Found #{@settings_dir}/#{fname}. Remove it? (y/n) ", :yellow end if yes File.delete("#{@settings_dir}/#{fname}") say_ok "---#{@settings_dir}/#{fname} deleted---" end end end |
#rm(modify_vimrc = true) ⇒ Object
1) Remove the line ‘Bundle plugin_name` or `Plugin plugin_name` from .vimrc. 2) Look for a file in the settings directory (provided by option –settings)
with name that includes the plugin name. Then ask if the user wants to remove it.
3) Remove the plugin directory.
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 61 62 |
# File 'lib/vundle_cli/uninstaller.rb', line 31 def rm(modify_vimrc = true) if modify_vimrc say "Searching plugin in #{@vimrc}..." tmp = Tempfile.new("vimrc_tmp") open(@vimrc, 'r').each { |l| if l.chomp =~ /(Bundle|Plugin) .*#{Regexp.quote(@plugin)}.*/ yes = true unless @force yes = agree? "Uninstall #{l.chomp} from vimrc? (y/n) ", :yellow end if yes say_ok "Uninstalling " say l.chomp.gsub(/(Bundle|Plugin|'|,|\s)/, '') next end end tmp << l } tmp.close FileUtils.mv(tmp.path, @vimrc) puts_separator end plugin_name = plugin_base_name(@plugin) say "Searching for setting file..." delete_setting_file(plugin_name) puts_separator say "Searching for plugin folder..." delete_plugin_dir(plugin_name) end |