infect 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +9 -1
- data/README.md +21 -2
- data/infect.gemspec +1 -0
- data/lib/infect/command.rb +2 -2
- data/lib/infect/command/bundle.rb +3 -2
- data/lib/infect/command/prereqs.rb +1 -1
- data/lib/infect/runner.rb +43 -3
- data/lib/infect/version.rb +1 -1
- data/spec/command_spec.rb +2 -2
- data/spec/runner_spec.rb +34 -0
- data/spec/standalone_spec.rb +1 -4
- data/standalone/infect +39 -15
- metadata +20 -2
data/Gemfile.lock
CHANGED
@@ -1,12 +1,18 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
infect (0.0.
|
4
|
+
infect (0.0.4)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
+
coderay (1.0.9)
|
9
10
|
diff-lcs (1.1.3)
|
11
|
+
method_source (0.8.1)
|
12
|
+
pry (0.9.12.2)
|
13
|
+
coderay (~> 1.0.5)
|
14
|
+
method_source (~> 0.8)
|
15
|
+
slop (~> 3.4)
|
10
16
|
rspec (2.12.0)
|
11
17
|
rspec-core (~> 2.12.0)
|
12
18
|
rspec-expectations (~> 2.12.0)
|
@@ -15,10 +21,12 @@ GEM
|
|
15
21
|
rspec-expectations (2.12.1)
|
16
22
|
diff-lcs (~> 1.1.3)
|
17
23
|
rspec-mocks (2.12.1)
|
24
|
+
slop (3.4.5)
|
18
25
|
|
19
26
|
PLATFORMS
|
20
27
|
ruby
|
21
28
|
|
22
29
|
DEPENDENCIES
|
23
30
|
infect!
|
31
|
+
pry
|
24
32
|
rspec
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# ☣ Infect
|
2
2
|
|
3
|
-
Bundle manager for [
|
3
|
+
Bundle manager for [Pathogen](https://github.com/tpope/vim-pathogen).
|
4
4
|
|
5
|
-
Manage your entire vim config with a single
|
5
|
+
Manage your entire vim config with a single `.vimrc` file. Much the same way that [sprockets](https://github.com/sstephenson/sprockets) lets you include web assets, infect will handle install vim plugins for you.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -18,6 +18,25 @@ Or if you prefer to manage it at a gem:
|
|
18
18
|
|
19
19
|
The point of Infect it to make it easy to manage your vim config. You should be able to check in your `.vimrc` into source control and use that one file to easily install any plugins you need.
|
20
20
|
|
21
|
+
## Rationale
|
22
|
+
|
23
|
+
Why invent another way of managing vim plugins?
|
24
|
+
|
25
|
+
* I want to be able to use my `.vimrc` when without installing plugins.
|
26
|
+
* I like having simple command line apps to manage my setup.
|
27
|
+
* I wanted to use pathogen to do the loading.
|
28
|
+
* I was tired of managing git submodules, nor did I find it very scalable.
|
29
|
+
|
30
|
+
|
31
|
+
Vundle is really slick, much nicer now than when I used it a few years ago. But I had two main problems with it:
|
32
|
+
|
33
|
+
* The `vimrc` is not usable unless vundle is installed. You will get errors on the config lines if you try to run vim with out the vundle plugin no installed. This is probably not normally a problem for most people, but I like to be able to scp my `.vimrc` to servers to get a basic configuration up there, but don't want to worry about installing the plugins.
|
34
|
+
* Vundle was slower than pathogen to load. Not sure if this is still the case, but at one point it added a noticable delay in loading vim.
|
35
|
+
* I don't really want to use my editor for installing stuff. Bram said "Each program has its own task and should be good at it" and think installing bundles is better suited for a command line script.
|
36
|
+
|
37
|
+
Like I said, [Vundle](https://github.com/gmarik/vundle) is really nice, quite polished and active. Just not for me, you may want to check it out.
|
38
|
+
|
39
|
+
|
21
40
|
## Usage
|
22
41
|
|
23
42
|
Infect reads your `.vimrc` file and looks for magic comments. It uses those to install pathogen style vim bundles. A minimal `.vimrc` to use with infect would look like this:
|
data/infect.gemspec
CHANGED
data/lib/infect/command.rb
CHANGED
@@ -5,10 +5,10 @@ module Infect
|
|
5
5
|
class Command
|
6
6
|
include Infect::Colorize
|
7
7
|
|
8
|
-
def self.build(command,
|
8
|
+
def self.build(command, arg ,opts)
|
9
9
|
case command.to_sym
|
10
10
|
when :bundle
|
11
|
-
Bundle.new(
|
11
|
+
Bundle.new(arg, opts)
|
12
12
|
else
|
13
13
|
$stderr.puts "WARNING: #{command} is not a valid command, ignorning"
|
14
14
|
end
|
@@ -2,8 +2,9 @@ module Infect
|
|
2
2
|
class Command
|
3
3
|
class Bundle < Command
|
4
4
|
attr_reader :bundle, :name, :location
|
5
|
-
def initialize(
|
6
|
-
@bundle =
|
5
|
+
def initialize(arg, opts)
|
6
|
+
@bundle = arg
|
7
|
+
@options = opts
|
7
8
|
@name = File.basename(bundle)
|
8
9
|
@location = File.expand_path("#{BUNDLE_DIR}/#{name}")
|
9
10
|
end
|
data/lib/infect/runner.rb
CHANGED
@@ -10,10 +10,10 @@ module Infect
|
|
10
10
|
|
11
11
|
commands = [Command::Prereqs.new()]
|
12
12
|
|
13
|
-
File.open( VIMRC ).
|
13
|
+
File.open( VIMRC ).each_line do |line|
|
14
14
|
if line =~ /^"=/
|
15
|
-
command,
|
16
|
-
commands << Command.build(command
|
15
|
+
command, arg, opts = parse_command(line.gsub('"=', ''))
|
16
|
+
commands << Command.build(command, arg, opts)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -24,5 +24,45 @@ module Infect
|
|
24
24
|
Cleanup.new(commands, :force => force).call
|
25
25
|
|
26
26
|
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def self.parse_command(line)
|
31
|
+
# TODO: pass in named params after for things like build commands and
|
32
|
+
# branches
|
33
|
+
#
|
34
|
+
# "bundle BundleName build: "make -f file", branch: awesome
|
35
|
+
#
|
36
|
+
# So this will split the command into 3 parts
|
37
|
+
# Now we can take args and split by ',' the split those by ':' and
|
38
|
+
# map that to a hash that we can pass into the command builder
|
39
|
+
|
40
|
+
# This splits adn perserves "quoted words"
|
41
|
+
#command, *args = line.split /\s(?=(?:[^"]|"[^"]*")*$)/
|
42
|
+
|
43
|
+
#command, *args = line.split
|
44
|
+
|
45
|
+
command, arg, opts_string = line.split ' ', 3
|
46
|
+
[command, arg, parse_opts(opts_string)]
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.parse_opts(string)
|
50
|
+
hash = {}
|
51
|
+
# Woah now.
|
52
|
+
#
|
53
|
+
# The first split and regex will perserver quoted strings" and split on
|
54
|
+
# whitespace or colons.
|
55
|
+
#
|
56
|
+
# The reject removes any duplicate empty strings that the split might
|
57
|
+
# create when it encounters a colon and space next to each other
|
58
|
+
# (something like this: ": " will do that)
|
59
|
+
parts = string.split(/[\s:](?=(?:[^"]|"[^"]*")*$)/).reject! { |c| c.empty? }
|
60
|
+
if parts
|
61
|
+
parts.each_slice(2) do |key, val|
|
62
|
+
hash[key.to_sym] = val
|
63
|
+
end
|
64
|
+
end
|
65
|
+
hash
|
66
|
+
end
|
27
67
|
end
|
28
68
|
end
|
data/lib/infect/version.rb
CHANGED
data/spec/command_spec.rb
CHANGED
@@ -2,10 +2,10 @@ require "./lib/infect"
|
|
2
2
|
|
3
3
|
describe Infect::Command do
|
4
4
|
it "build a nil class when given a bad command" do
|
5
|
-
Infect::Command.build("blargl",
|
5
|
+
Infect::Command.build("blargl", "bangle", {}).should be_nil
|
6
6
|
end
|
7
7
|
|
8
8
|
it "build a bundle command" do
|
9
|
-
Infect::Command.build("bundle",
|
9
|
+
Infect::Command.build("bundle", "tpope/vim-pathogen", {}).name.should == "vim-pathogen"
|
10
10
|
end
|
11
11
|
end
|
data/spec/runner_spec.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "./lib/infect"
|
2
|
+
require 'tempfile'
|
3
|
+
require 'pry'
|
4
|
+
require 'tmpdir'
|
5
|
+
|
6
|
+
describe Infect::Runner do
|
7
|
+
before do
|
8
|
+
stub_const "Infect::VIMRC", file
|
9
|
+
stub_const "Infect::BUNDLE_DIR", dir
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:file) { Tempfile.new("rspec") }
|
13
|
+
let(:dir) { Dir.mktmpdir }
|
14
|
+
|
15
|
+
it "reads bundle command" do
|
16
|
+
file.puts '"=bundle NoParams'
|
17
|
+
file.close
|
18
|
+
|
19
|
+
Infect::Command.stub(:builder)
|
20
|
+
Infect::Command.should_receive(:build).with("bundle", "NoParams", {})
|
21
|
+
Infect::Runner.call
|
22
|
+
end
|
23
|
+
|
24
|
+
it "reads bundle command" do
|
25
|
+
file.puts '"=bundle ExtraParams param1:val1 param2: val2'
|
26
|
+
file.close
|
27
|
+
|
28
|
+
Infect::Command.stub(:builder)
|
29
|
+
Infect::Command.should_receive(:build).with("bundle", "ExtraParams", {param1:"val1", param2:"val2"})
|
30
|
+
Infect::Runner.call
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
end
|
data/spec/standalone_spec.rb
CHANGED
data/standalone/infect
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
#
|
8
8
|
|
9
9
|
module Infect
|
10
|
-
VERSION = "0.0.
|
10
|
+
VERSION = "0.0.4"
|
11
11
|
end
|
12
12
|
|
13
13
|
require 'open-uri'
|
@@ -35,10 +35,10 @@ module Infect
|
|
35
35
|
class Command
|
36
36
|
include Infect::Colorize
|
37
37
|
|
38
|
-
def self.build(command,
|
38
|
+
def self.build(command, arg ,opts)
|
39
39
|
case command.to_sym
|
40
40
|
when :bundle
|
41
|
-
Bundle.new(
|
41
|
+
Bundle.new(arg, opts)
|
42
42
|
else
|
43
43
|
$stderr.puts "WARNING: #{command} is not a valid command, ignorning"
|
44
44
|
end
|
@@ -72,8 +72,9 @@ module Infect
|
|
72
72
|
class Command
|
73
73
|
class Bundle < Command
|
74
74
|
attr_reader :bundle, :name, :location
|
75
|
-
def initialize(
|
76
|
-
@bundle =
|
75
|
+
def initialize(arg, opts)
|
76
|
+
@bundle = arg
|
77
|
+
@options = opts
|
77
78
|
@name = File.basename(bundle)
|
78
79
|
@location = File.expand_path("#{BUNDLE_DIR}/#{name}")
|
79
80
|
end
|
@@ -112,19 +113,21 @@ module Infect
|
|
112
113
|
end
|
113
114
|
end
|
114
115
|
|
116
|
+
require 'fileutils'
|
115
117
|
module Infect
|
116
118
|
class Command
|
117
119
|
class Prereqs < Command
|
120
|
+
def mkdirs(list)
|
121
|
+
list.each do |path|
|
122
|
+
FileUtils.mkdir_p(File.expand_path(path))
|
123
|
+
end
|
124
|
+
end
|
118
125
|
def call
|
119
|
-
|
126
|
+
mkdir "~/.vim/bundle"
|
120
127
|
if RUBY_PLATFORM =~ /darwin/
|
121
|
-
|
122
|
-
mkdir_p "~/Library/Vim/backup"
|
123
|
-
mkdir_p "~/Library/Vim/undo"
|
128
|
+
mkdirs %w(~/Library/Vim/swap ~/Library/Vim/backup ~/Library/Vim/undo)
|
124
129
|
else
|
125
|
-
|
126
|
-
mkdir_p "~/.local/share/vim/backup"
|
127
|
-
mkdir_p "~/.local/share/vim/undo"
|
130
|
+
mkdirs %w(~/.local/share/vim/swap ~/.local/share/vim/backup ~/.local/share/vim/undo")
|
128
131
|
end
|
129
132
|
end
|
130
133
|
end
|
@@ -200,10 +203,10 @@ module Infect
|
|
200
203
|
|
201
204
|
commands = [Command::Prereqs.new()]
|
202
205
|
|
203
|
-
File.open( VIMRC ).
|
206
|
+
File.open( VIMRC ).each_line do |line|
|
204
207
|
if line =~ /^"=/
|
205
|
-
command,
|
206
|
-
commands << Command.build(command
|
208
|
+
command, arg, opts = parse_command(line.gsub('"=', ''))
|
209
|
+
commands << Command.build(command, arg, opts)
|
207
210
|
end
|
208
211
|
end
|
209
212
|
|
@@ -214,6 +217,27 @@ module Infect
|
|
214
217
|
Cleanup.new(commands, :force => force).call
|
215
218
|
|
216
219
|
end
|
220
|
+
|
221
|
+
private
|
222
|
+
|
223
|
+
def self.parse_command(line)
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
command, arg, opts_string = line.split ' ', 3
|
228
|
+
[command, arg, parse_opts(opts_string)]
|
229
|
+
end
|
230
|
+
|
231
|
+
def self.parse_opts(string)
|
232
|
+
hash = {}
|
233
|
+
parts = string.split(/[\s:](?=(?:[^"]|"[^"]*")*$)/).reject! { |c| c.empty? }
|
234
|
+
if parts
|
235
|
+
parts.each_slice(2) do |key, val|
|
236
|
+
hash[key.to_sym] = val
|
237
|
+
end
|
238
|
+
end
|
239
|
+
hash
|
240
|
+
end
|
217
241
|
end
|
218
242
|
end
|
219
243
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: infect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-08-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: pry
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
30
46
|
description: Asset Pipeline for Pathogen.vim
|
31
47
|
email:
|
32
48
|
- csexton@gmail.com
|
@@ -54,6 +70,7 @@ files:
|
|
54
70
|
- lib/infect/standalone.rb
|
55
71
|
- lib/infect/version.rb
|
56
72
|
- spec/command_spec.rb
|
73
|
+
- spec/runner_spec.rb
|
57
74
|
- spec/standalone_spec.rb
|
58
75
|
- standalone/infect
|
59
76
|
homepage: https://github.com/csexton/infect
|
@@ -83,4 +100,5 @@ summary: Asset Pipeline for Vim and Pathogen, install vim bundles included in yo
|
|
83
100
|
vimrc
|
84
101
|
test_files:
|
85
102
|
- spec/command_spec.rb
|
103
|
+
- spec/runner_spec.rb
|
86
104
|
- spec/standalone_spec.rb
|