vundle-cli 0.0.6 → 0.0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c75d3d265b458ba55a4ce2e79d746650fdb1250
4
- data.tar.gz: 4795a1f6a38add4462c5842eb9c364278310d174
3
+ metadata.gz: c1da6a2d4b8bba91de6d6e04ff69f43871c8c8d0
4
+ data.tar.gz: f3365cbef0211b7a066ac193972610f3b042a7fd
5
5
  SHA512:
6
- metadata.gz: 8763579a37533c6b81b12821b84640576818fecbb3fc5f58dadfbdf39a5603f2ab0e3e361197dbbfad07df2b318f586e9f9f96995755815f5848d29bcd45e16e
7
- data.tar.gz: 9e4f9f63a71c68db50cd7259c65f6454a6ddb9c64c8904134d642388bb1381e4cd7fd5769ee67b7fb615d2674dd08a2cfc28d5263f2be5841479afb353291ca0
6
+ metadata.gz: a2eef73a0c08858783fc1eb6d50a8af7f9532eeebe54e91c430f98fa6d7b5c4cbceaa293a3fdfea5eaa94f6bf92b83939d50f58d55c26eabcd6a06780c8cf47b
7
+ data.tar.gz: 3a64a0c7f55ddf107360633de23084b5cfd8b220ce55752febddd8cdf69558011d4a366e609bd783353f83501abda876e15ca8d99e5483c5651a79a46e93a8f1
data/README.md CHANGED
@@ -4,15 +4,17 @@ A (tiny) CLI for Vim plugin manager [Vundle](https://github.com/gmarik/Vundle.vi
4
4
 
5
5
  Available commands:
6
6
 
7
- * `rm` remove a bundle
8
- * `list` list all installed bundles
9
- * `find` find an installed bundle
7
+ * `rm` remove a plugin
8
+ * `list` list all installed plugins
9
+ * `find` find an installed plugin
10
+ * `clean` clean up unused plugin related files
10
11
 
11
- `rm` will remove the line `Bundle bundle_name` in your `.vimrc` and look
12
- for a configuration file for this bundle in the specified settings directory,
13
- then it will ask if you want to remove the file or not.
12
+ `rm` will remove the line `Bundle plugin_name` or `Plugin plugin_name` in your `.vimrc`,
13
+ delete the configuration file for this plugin in the specified settings directory,
14
+ and the plugin folder. Before anything is deleted, the command will prompt you
15
+ for confirmation unless the `--force` switch is on.
14
16
 
15
- I built this so that it's quicker to uninstall a bundle with my particular
17
+ I built this so that it's quicker to uninstall a plugin with my particular
16
18
  [vim setup](https://github.com/baopham/vim)
17
19
 
18
20
  ## Installation
@@ -23,7 +25,7 @@ Add this line to your application's Gemfile:
23
25
 
24
26
  And then execute:
25
27
 
26
- $ bundle
28
+ $ vundle
27
29
 
28
30
  Or install it yourself as:
29
31
 
@@ -41,10 +43,11 @@ Or install it yourself as:
41
43
 
42
44
  **COMMANDS**:
43
45
 
44
- find Search for an installed bundle
46
+ clean Clean up unused plugin related files
47
+ find Search for an installed plugin
45
48
  help Display global or [command] help documentation
46
- list List all installed bundles
47
- rm Remove a bundle
49
+ list List all installed plugins
50
+ rm Remove a plugin
48
51
 
49
52
  **GLOBAL OPTIONS**:
50
53
 
data/bin/vundle CHANGED
@@ -7,35 +7,40 @@ require 'vundle_cli'
7
7
 
8
8
  program :version, VundleCli::VERSION
9
9
  program :description, 'A (tiny) CLI for Vim plugin manager Vundle'
10
-
10
+
11
11
  command :rm do |c|
12
- c.syntax = 'vundle rm <bundle> [options]'
13
- c.summary = 'Remove a bundle'
14
- c.description = 'Uninstall a bundle.
15
- This will remove the line `Bundle <bundle>` in your .vimrc
16
- and will prompt you for confirmation before deleting the bundle\'s config file if found.'
17
- c.example 'Remove bundle kien/ctrlp.vim', 'vundle rm kien/ctrlp.vim'
18
- c.option '--vimdir vimdir', 'Vim directory. Default to ~/.vim'
12
+ c.syntax = 'vundle rm <plugin> [options]'
13
+ c.summary = 'Remove a plugin'
14
+ c.description = "Uninstall a plugin.
15
+ The command will remove the line ``Bundle plugin_name'' or ``Plugin plugin_name'' in your ``.vimrc'',
16
+ delete the configuration file for this plugin in the specified settings directory, and the plugin folder.
17
+ Before anything is deleted, the command will prompt you for confirmation unless the ``--force'' switch is on."
18
+ c.example 'Remove plugin kien/ctrlp.vim', 'vundle rm kien/ctrlp.vim'
19
+ c.example "Or, remove any plugin that has ``ctrlp'' in its name (not recommended, it can be too ambiguous)", 'vundle rm ctrlp'
20
+ c.option '--vimdir vimdir', 'Vim directory. Default to ~/.vim.'
19
21
  c.option '--settings settings_dir',
20
- 'Vim settings directory (where you configure your bundles). Default to ~/.vim/settings'
21
- c.option '--vimrc vimrc', '.vimrc path. Default to ~/.vimrc'
22
+ 'Vim settings directory (where you configure your plugins). Default to ~/.vim/settings.'
23
+ c.option '--vimrc vimrc', '.vimrc path. Default to ~/.vimrc.'
24
+ c.option '-f', '--force', 'Force delete without confirmation. Disabled by default.'
22
25
  c.action do |args, options|
23
- bundle = args.shift || abort('Bundle argument required.')
26
+ plugin = args.shift || abort('Plugin argument required.')
24
27
  options.default \
25
28
  :vimdir => '~/.vim',
26
29
  :settings => '~/.vim/settings',
27
- :vimrc => '~/.vimrc'
28
- runner = VundleCli::Uninstaller.new(options, bundle)
30
+ :vimrc => '~/.vimrc',
31
+ :force => false
32
+ runner = VundleCli::Uninstaller.new(options, plugin)
29
33
  runner.rm
34
+ say_ok "Done!"
30
35
  end
31
36
  end
32
37
 
33
38
  command :list do |c|
34
39
  c.syntax = 'vundle list [options]'
35
- c.summary = 'List all installed bundles'
36
- c.description = 'List all installed bundles'
37
- c.example '', 'vundle list --vimrc ~/.vimrc'
38
- c.option '--vimrc vimrc', '.vimrc path. Default to ~/.vimrc'
40
+ c.summary = 'List all installed plugins'
41
+ c.description = 'List all installed plugins'
42
+ c.example 'List all installed plugins', 'vundle list --vimrc ~/.vimrc'
43
+ c.option '--vimrc vimrc', '.vimrc path. Default to ~/.vimrc.'
39
44
  c.action do |args, options|
40
45
  options.default \
41
46
  :vimrc => '~/.vimrc'
@@ -45,16 +50,49 @@ command :list do |c|
45
50
  end
46
51
 
47
52
  command :find do |c|
48
- c.syntax = 'vundle find bundle [options]'
49
- c.summary = 'Search for an installed bundle'
50
- c.description = 'Search for an installed bundle'
51
- c.example 'Find a bundle that has substring `gist`', 'vundle find gist'
52
- c.option '--vimrc vimrc', '.vimrc path. Default to ~/.vimrc'
53
+ c.syntax = 'vundle find <plugin> [options]'
54
+ c.summary = 'Search for an installed plugin'
55
+ c.description = 'Search for an installed plugin'
56
+ c.example "Find a plugin that has substring ``gist''", 'vundle find gist'
57
+ c.option '--vimrc vimrc', '.vimrc path. Default to ~/.vimrc.'
53
58
  c.action do |args, options|
54
- bundle = args.shift || abort('Bundle argument required.')
59
+ plugin = args.shift || abort('Plugin argument required.')
55
60
  options.default \
56
61
  :vimrc => '~/.vimrc'
57
- finder = VundleCli::Finder.new(options, bundle)
62
+ finder = VundleCli::Finder.new(options, plugin)
58
63
  finder.find
59
64
  end
60
65
  end
66
+
67
+ command :clean do |c|
68
+ c.syntax = 'vundle clean [plugin] [options]'
69
+ c.summary = 'Clean up unused plugin related files'
70
+ c.description = "Clean up unused plugin related files (such as plugin folder and config file).
71
+ It will prompt you for confirmation before deleting anything (unless force switch is on).
72
+ For option ``--all'', the command gets a list of the plugins in your bundle folder (e.g: ~/.vim/bundle)
73
+ and compare them with the plugins in your vimrc in order to determine which plugins need to be cleaned up."
74
+ c.example 'Clean all unused plugins', 'vundle clean --all'
75
+ c.example 'Clean plugin vim-signify', 'vundle clean vim-signify'
76
+ c.example "Clean any plugins with names that have substring ``dirty''", 'vundle clean dirty'
77
+ c.option '--vimdir vimdir', 'Vim directory. Default to ~/.vim.'
78
+ c.option '--settings settings_dir',
79
+ 'Vim settings directory (where you configure your plugins). Default to ~/.vim/settings.'
80
+ c.option '--vimrc vimrc', '.vimrc path. Default to ~/.vimrc.'
81
+ c.option '-a', '--all', 'Delete everything that is not installed in your vimrc. Disabled by default.'
82
+ c.option '-l', '--list', 'List all unused plugins.'
83
+ c.option '-f', '--force', 'Force delete files without prompt. Disabled by default.'
84
+ c.action do |args, options|
85
+ plugin = args.shift
86
+ unless options.all or options.list
87
+ abort('Plugin argument required.') if plugin.nil?
88
+ end
89
+ options.default \
90
+ :vimdir => '~/.vim',
91
+ :settings => '~/.vim/settings',
92
+ :vimrc => '~/.vimrc',
93
+ :force => false
94
+ cleaner = VundleCli::Cleaner.new(options, plugin)
95
+ cleaner.clean
96
+ say_ok "Done!"
97
+ end
98
+ end
data/lib/vundle_cli.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require "vundle_cli/version"
2
2
  require "vundle_cli/uninstaller"
3
3
  require "vundle_cli/finder"
4
- require "vundle_cli/helpers"
4
+ require "vundle_cli/cleaner"
5
+ require "vundle_cli/helper"
6
+ require "vundle_cli/import"
@@ -0,0 +1,67 @@
1
+ module VundleCli
2
+
3
+ class Cleaner
4
+
5
+ attr_reader :options, :vimdir, :settings_dir, :vimrc, :all, :force, :plugin
6
+
7
+ def initialize(options, plugin)
8
+ @options = options
9
+ @vimdir = file_validate(options.vimdir, true)
10
+ @settings_dir = file_validate(options.settings, true)
11
+ @vimrc = file_validate(options.vimrc)
12
+ @all = options.all
13
+ @force = options.force
14
+ @plugin = plugin
15
+ end
16
+
17
+ def clean
18
+ if @all or @options.list
19
+ unused_plugins = get_list
20
+ end
21
+
22
+ if @options.list
23
+ say "Unused plugins:"
24
+ say unused_plugins.join("\n") unless unused_plugins.empty?
25
+ puts_separator
26
+ end
27
+ if @all
28
+ uninstaller = Uninstaller.new(@options)
29
+ unused_plugins.each do |plugin_name|
30
+ say "Cleaning #{plugin_name}..."
31
+ uninstaller.delete_setting_file(plugin_name)
32
+ uninstaller.delete_plugin_dir(plugin_name)
33
+ end
34
+ elsif not @plugin.nil?
35
+ # Only clean up unused plugin.
36
+ open(@vimrc, 'r').each { |l|
37
+ next unless l.chomp =~ /(Bundle|Plugin) .*#{Regexp.quote(@plugin)}.*/
38
+ say_error "Can't clean this plugin since it's installed in your .vimrc. Please use command `rm` to uninstall it."
39
+ return
40
+ }
41
+
42
+ uninstaller = Uninstaller.new(@options, @plugin)
43
+ uninstaller.rm(false)
44
+ end
45
+ end
46
+
47
+ # Get a list of unused plugins.
48
+ def get_list
49
+ # Get a list of plugin directories (basenames only).
50
+ all_plugins = Array.new
51
+ all_plugins = Dir["#{@vimdir}/bundle/*/"].map { |b|
52
+ File.basename(b)
53
+ }
54
+
55
+ # Get a list of installed plugins.
56
+ finder = Finder.new(@options)
57
+ installed_plugins = Array.new
58
+ installed_plugins = finder.get_list.map { |b|
59
+ plugin_base_name(b)
60
+ }
61
+
62
+ all_plugins - installed_plugins
63
+ end
64
+
65
+ end
66
+
67
+ end
@@ -1,34 +1,40 @@
1
1
  module VundleCli
2
2
  class Finder
3
3
 
4
- attr_reader :options
4
+ attr_reader :options, :vimrc, :plugin
5
5
 
6
- attr_reader :vimrc
7
-
8
- attr_reader :bundle
9
-
10
- def initialize(options, bundle = '')
6
+ def initialize(options, plugin = '')
11
7
  @options = options
12
- @vimrc = Helpers.file_validate(options.vimrc)
13
- @bundle = bundle
8
+ @vimrc = file_validate(options.vimrc)
9
+ @plugin = plugin
14
10
  end
15
11
 
16
- def list
12
+ def get_list
13
+ plugins = Array.new
17
14
  open(@vimrc, 'r').each { |l|
18
- matches = l.chomp.match(/^Bundle (\S*)/)
15
+ matches = l.chomp.match(/^(Bundle|Plugin) (\S*)/)
19
16
  if matches
20
- puts matches[1].gsub("'", '')
17
+ plugins << matches[2].gsub(/[',]/, '')
21
18
  end
22
19
  }
20
+ plugins
21
+ end
22
+
23
+ def list
24
+ enable_paging
25
+ say get_list.join("\n")
23
26
  end
24
27
 
25
28
  def find
26
- puts "Searching..."
29
+ say "Searching..."
27
30
  open(@vimrc, 'r').each { |l|
28
- matches = l.chomp.match(/^Bundle (\S*)/)
31
+ matches = l.chomp.match(/^(Bundle|Plugin) (\S*)/)
29
32
  if matches
30
- bundle = matches[1].gsub("'", '')
31
- puts "Found #{bundle}" if bundle.downcase.include?(@bundle.downcase)
33
+ plugin = matches[2].gsub(/[',]/, '')
34
+ if plugin.downcase.include?(@plugin.downcase)
35
+ say_ok "Found "
36
+ say plugin
37
+ end
32
38
  end
33
39
  }
34
40
  end
@@ -1,5 +1,5 @@
1
1
  module VundleCli
2
- module Helpers
2
+ module Helper
3
3
  module_function
4
4
 
5
5
  def file_validate(fpath, check_dir = false)
@@ -23,5 +23,28 @@ module VundleCli
23
23
 
24
24
  fpath
25
25
  end
26
+
27
+ def plugin_base_name(plugin)
28
+ File.basename(plugin)
29
+ end
30
+
31
+ # Get the trimmed name of the plugin,
32
+ # e.g. remove prefix, suffix "vim-", "-vim", ".vim".
33
+ def plugin_trim_name(plugin_name)
34
+ plugin_name.gsub(/(vim-|-vim|\.vim)/, '')
35
+ end
36
+
37
+ def puts_separator
38
+ say "-----------------------------"
39
+ end
40
+
41
+ def agree?(message, color = nil)
42
+ begin
43
+ message = $terminal.color(message, color) unless color.nil?
44
+ agree(message)
45
+ rescue Interrupt
46
+ abort("\nAbort.")
47
+ end
48
+ end
26
49
  end
27
50
  end
@@ -0,0 +1,3 @@
1
+ require 'vundle_cli'
2
+
3
+ include VundleCli::Helper
@@ -5,59 +5,99 @@ module VundleCli
5
5
 
6
6
  class Uninstaller
7
7
 
8
- attr_reader :options
8
+ attr_reader :options, :vimdir, :settings_dir, :vimrc, :force, :plugin
9
9
 
10
- attr_reader :vimdir
11
-
12
- attr_reader :settings_dir
13
-
14
- attr_reader :vimrc
15
-
16
- attr_reader :bundle
17
-
18
- def initialize(options, bundle)
10
+ def initialize(options, plugin = nil)
19
11
  @options = options
20
- @vimdir = Helpers.file_validate(options.vimdir, true)
21
- @settings_dir = Helpers.file_validate(options.settings, true)
22
- @vimrc = Helpers.file_validate(options.vimrc)
23
- @bundle = bundle
12
+ @vimdir = file_validate(options.vimdir, true)
13
+ @settings_dir = file_validate(options.settings, true)
14
+ @vimrc = file_validate(options.vimrc)
15
+ @force = options.force
16
+ unless plugin.nil?
17
+ @plugin = plugin
18
+ abort("Plugin name too ambiguous.") if ambiguous?(plugin)
19
+ end
24
20
  end
25
21
 
26
- # 1) Remove the line `Bundle bundle` from .vimrc.
22
+ def ambiguous?(plugin)
23
+ plugin_name = plugin_base_name(plugin)
24
+ plugin_trim_name(plugin_name).empty?
25
+ end
26
+
27
+ # 1) Remove the line `Bundle plugin_name` or `Plugin plugin_name` from .vimrc.
27
28
  # 2) Look for a file in the settings directory (provided by option --settings)
28
- # with name that includes the bundle name. Then ask if the user wants to remove it.
29
- def rm
30
- tmp = Tempfile.new("vimrc_tmp")
31
- open(@vimrc, 'r').each { |l|
32
- if l.chomp =~ /Bundle .*#{Regexp.quote(@bundle)}.*/
33
- puts "Found bundle #{@bundle}, removing it from #{@vimrc}..."
34
- else
29
+ # with name that includes the plugin name. Then ask if the user wants to remove it.
30
+ # 3) Remove the plugin directory.
31
+ def rm(modify_vimrc = true)
32
+
33
+ if modify_vimrc
34
+ say "Searching plugin in #{@vimrc}..."
35
+ tmp = Tempfile.new("vimrc_tmp")
36
+ open(@vimrc, 'r').each { |l|
37
+ if l.chomp =~ /(Bundle|Plugin) .*#{Regexp.quote(@plugin)}.*/
38
+ yes = true
39
+ unless @force
40
+ yes = agree? "Uninstall #{l.chomp} from vimrc? (y/n) ", :yellow
41
+ end
42
+ if yes
43
+ say_ok "Uninstalling "
44
+ say l.chomp.gsub(/(Bundle|Plugin|'|,|\s)/, '')
45
+ next
46
+ end
47
+ end
35
48
  tmp << l
36
- end
37
- }
38
- tmp.close
39
- FileUtils.mv(tmp.path, @vimrc)
49
+ }
50
+ tmp.close
51
+ FileUtils.mv(tmp.path, @vimrc)
52
+ puts_separator
53
+ end
40
54
 
41
- puts "Searching for setting file..."
55
+ plugin_name = plugin_base_name(@plugin)
42
56
 
43
- # Get the bundle's main name.
44
- # (the provided @bundle usually looks like baopham/trailertrash.vim,
45
- # so we trim it down to get "trailertrash" only).
46
- bundle_name = @bundle
47
- if @bundle.include?("/")
48
- bundle_name = @bundle.split("/")[1].sub(/\.vim/, '')
49
- end
57
+ say "Searching for setting file..."
58
+ delete_setting_file(plugin_name)
59
+ puts_separator
60
+ say "Searching for plugin folder..."
61
+ delete_plugin_dir(plugin_name)
62
+ end
50
63
 
64
+ def delete_setting_file(plugin_name)
65
+ trimmed_name = plugin_trim_name(plugin_name)
51
66
  Dir.foreach(@settings_dir) do |fname|
52
- next unless fname.downcase.include?(bundle_name.downcase)
53
- puts "Found #{@settings_dir}/#{fname} setting file. Remove it? (yes/no) "
54
- input = STDIN.gets.chomp
55
- if input == 'yes'
67
+ next if fname == '.' or fname == '..'
68
+ next unless fname.downcase.include?(trimmed_name.downcase)
69
+ yes = true
70
+ unless @force
71
+ yes = agree? "Found #{@settings_dir}/#{fname}. Remove it? (y/n) ", :yellow
72
+ end
73
+ if yes
56
74
  File.delete("#{@settings_dir}/#{fname}")
57
- puts "File deleted."
75
+ say_ok "---#{@settings_dir}/#{fname} deleted---"
58
76
  end
59
77
  end
60
78
  end
61
79
 
80
+ def delete_plugin_dir(plugin_name)
81
+ plugin_dir = "#{@vimdir}/bundle/#{plugin_name}"
82
+ dirs =
83
+ # If the user uses the exact name of the plugin, remove it.
84
+ if Dir.exists?(plugin_dir)
85
+ [plugin_dir]
86
+ # else, search for plugin folders with substring plugin_name.
87
+ else
88
+ Dir["#{@vimdir}/bundle/*#{plugin_name}*"]
89
+ end
90
+
91
+ dirs.each { |b|
92
+ yes = true
93
+ unless @force
94
+ yes = agree? "Found #{b}. Remove it? (y/n) ", :yellow
95
+ end
96
+ if yes
97
+ FileUtils.rm_rf(b)
98
+ say_ok "---#{b} deleted---"
99
+ end
100
+ }
101
+ end
62
102
  end
63
103
  end
@@ -1,3 +1,3 @@
1
1
  module VundleCli
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7.1"
3
3
  end
data/vundle-cli.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Bao Pham"]
10
10
  spec.email = ["gbaopham@gmail.com"]
11
11
  spec.summary = %q{A tiny CLI for Vim plugin manager Vundle}
12
- spec.description = %q{Available commands: rm, list, find to remove, list and find installed bundles}
12
+ spec.description = %q{Available commands: rm, list, find, clean to remove, list, find installed plugins and clean up unused plugins}
13
13
  spec.homepage = "https://github.com/baopham/vundle-cli"
14
14
  spec.license = "MIT"
15
15
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vundle-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bao Pham
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-12 00:00:00.000000000 Z
11
+ date: 2014-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,8 +52,8 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '4.2'
55
- description: 'Available commands: rm, list, find to remove, list and find installed
56
- bundles'
55
+ description: 'Available commands: rm, list, find, clean to remove, list, find installed
56
+ plugins and clean up unused plugins'
57
57
  email:
58
58
  - gbaopham@gmail.com
59
59
  executables:
@@ -68,8 +68,10 @@ files:
68
68
  - Rakefile
69
69
  - bin/vundle
70
70
  - lib/vundle_cli.rb
71
+ - lib/vundle_cli/cleaner.rb
71
72
  - lib/vundle_cli/finder.rb
72
- - lib/vundle_cli/helpers.rb
73
+ - lib/vundle_cli/helper.rb
74
+ - lib/vundle_cli/import.rb
73
75
  - lib/vundle_cli/uninstaller.rb
74
76
  - lib/vundle_cli/version.rb
75
77
  - vundle-cli.gemspec