infect 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- infect (0.0.1)
4
+ infect (0.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,32 +1,31 @@
1
- # Infect
1
+ # ☣ Infect
2
2
 
3
- Asset Pipeline for Vim and Pathogen
3
+ Asset Pipeline Bundler for Vim and Pathogen
4
4
 
5
5
  ## Installation
6
6
 
7
+ Infect has no dependencies other than a recentish version of ruby. And can be installed as a standalone script, perhaps in your `~/bin` directory.
8
+
9
+ $ curl https://raw.github.com/csexton/infect/master/standalone/infect > ~/bin/infect && chmod +x ~/bin/infect
10
+
11
+ Or if you prefer to manage it at a gem:
12
+
7
13
  $ gem install infect
8
14
 
9
15
  ## Objective
10
16
 
11
- The point of Infect it to make it easy to manage your vim config. You should be able to check in yoru `.vimrc` into source control and use that one file to easily install any plugins you need.
17
+ 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.
12
18
 
13
19
  ## Usage
14
20
 
15
- Infect reads your `.vimrc` file and looks for magic comments. It uses those to install pathogen style vim bundles.
16
-
17
- " Include bundle:
18
- "=bundle tpope/vim-pathogen
19
- "=bundle tpope/vim-sensible
20
- "=bundle csexton/trailertrash.vim
21
-
22
- A minimal vimrc to use with infect would look like this:
21
+ 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:
23
22
 
24
- " vim bundles:
25
23
  "=bundle tpope/vim-pathogen
26
24
  "=bundle tpope/vim-sensible
27
25
  source ~/.vim/bundle/vim-pathogen/autoload/pathogen.vim
28
- execute pathogen#infect()
26
+ execute pathogen#runtime_append_all_bundles()
29
27
  syntax on
30
28
  filetype plugin indent on
31
29
 
30
+ Just put those lines at the top of your vimrc and infect will install pathogen and the bundles for you.
32
31
 
data/Rakefile CHANGED
@@ -1,6 +1,14 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
2
3
 
3
- desc "Compile infect into a single file"
4
- task :compile do
5
- puts "yay"
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task :default => :spec
6
+
7
+ file "./standalone/infect" => FileList.new("lib/infect.rb", "lib/infect/*.rb") do |task|
8
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
9
+ require 'infect/standalone'
10
+ Infect::Standalone.save("./standalone/infect")
6
11
  end
12
+
13
+ desc "Build standalone script"
14
+ task :standalone => "./standalone/infect"
data/bin/infect CHANGED
@@ -1,6 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- require 'optparse'
4
2
  require "#{File.dirname(__FILE__)}/../lib/infect"
5
3
 
6
- Infect.run
4
+ Infect::Runner.call(*ARGV)
@@ -1,27 +1,9 @@
1
1
  lib = File.expand_path('..', __FILE__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require 'infect/version'
4
+ require 'infect/colorize'
4
5
  require 'infect/command'
5
6
  require 'infect/command/bundle'
6
-
7
- module Infect
8
- # Globals be global
9
- VIMHOME = ENV['VIM'] || "#{ENV['HOME']}/.vim"
10
- VIMRC = ENV['MYVIMRC'] || "#{ENV['HOME']}/.vimrc"
11
-
12
-
13
- def self.run
14
- commands = []
15
-
16
- File.open( VIMRC ).each do |line|
17
- if line =~ /^"=/
18
- command, *args = line.split
19
- commands << Command.build(command.gsub('"=', ''), args)
20
- end
21
- end
22
-
23
- commands.compact.each do |command|
24
- command.call
25
- end
26
- end
27
- end
7
+ require 'infect/command/prereqs'
8
+ require 'infect/cleanup'
9
+ require 'infect/runner'
@@ -0,0 +1,57 @@
1
+ module Infect
2
+ class Cleanup
3
+ include Infect::Colorize
4
+ attr_reader :commands, :force
5
+
6
+ def initialize(commands, args = {})
7
+ @commands = commands
8
+ @force = args[:force] || false
9
+ end
10
+
11
+ def call
12
+ uninstall_unless_included names
13
+ end
14
+
15
+ private
16
+
17
+ def uninstall_unless_included(list)
18
+ Dir["#{BUNDLE_DIR}/*"].each do |path|
19
+ unless list.include? File.basename(path)
20
+ if confirm(path)
21
+ notice "Deleting #{path}"
22
+ require 'fileutils'
23
+ FileUtils.rm_rf path
24
+ else
25
+ notice "Leaving #{path}"
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ def confirm(name)
32
+ unless force
33
+ print "Remove #{name}? [Yn]: "
34
+ response = STDIN.gets.chomp
35
+ case response.downcase
36
+ when ''
37
+ true
38
+ when 'y'
39
+ true
40
+ else
41
+ false
42
+ end
43
+ end
44
+ end
45
+
46
+ def names
47
+ list = []
48
+ commands.each do |command|
49
+ if command.respond_to? :name
50
+ list << command.name
51
+ end
52
+ end
53
+ list
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,17 @@
1
+ require 'open-uri'
2
+ require 'fileutils'
3
+
4
+ module Infect
5
+ module Colorize
6
+ def colorize(code, str)
7
+ "\e[#{code}m#{str}\e[0m"
8
+ end
9
+ def notice(str)
10
+ puts colorize(32, str)
11
+ end
12
+ def error(str)
13
+ puts colorize(31, str)
14
+ end
15
+ end
16
+ end
17
+
@@ -3,6 +3,8 @@ require 'fileutils'
3
3
 
4
4
  module Infect
5
5
  class Command
6
+ include Infect::Colorize
7
+
6
8
  def self.build(command, args)
7
9
  case command.to_sym
8
10
  when :bundle
@@ -15,8 +17,13 @@ module Infect
15
17
  protected
16
18
 
17
19
  def mkdir(path)
18
- FileUtils.mkdir_p(File.expand_path(path))
20
+ expanded_path = File.expand_path(path)
21
+ unless File.directory?(expanded_path)
22
+ notice "Making dir #{path}"
23
+ FileUtils.mkdir_p(expanded_path)
24
+ end
19
25
  end
26
+
20
27
  def chdir(path)
21
28
  Dir.chdir(path)
22
29
  end
@@ -28,16 +35,5 @@ module Infect
28
35
  end
29
36
  end
30
37
  end
31
-
32
- def colorize(code, str)
33
- "\e[#{code}m#{str}\e[0m"
34
- end
35
- def notice(str)
36
- puts colorize(32, str)
37
- end
38
- def error(str)
39
- puts colorize(31, str)
40
- end
41
-
42
38
  end
43
39
  end
@@ -5,7 +5,7 @@ module Infect
5
5
  def initialize(args)
6
6
  @bundle = args[0]
7
7
  @name = File.basename(bundle)
8
- @location = File.expand_path("~/.vim/bundle/#{name}")
8
+ @location = File.expand_path("#{BUNDLE_DIR}/#{name}")
9
9
  end
10
10
 
11
11
  def url
@@ -14,8 +14,8 @@ module Infect
14
14
 
15
15
  def install
16
16
  notice "Installing #{name}... "
17
- mkdir "~/.vim/bundle"
18
- chdir "#{VIMHOME}/bundle"
17
+ mkdir BUNDLE_DIR
18
+ chdir BUNDLE_DIR
19
19
  git "clone '#{url}'"
20
20
  end
21
21
 
@@ -0,0 +1,20 @@
1
+ module Infect
2
+ class Command
3
+ class Prereqs < Command
4
+ def call
5
+ mkdir_p "~/.vim/bundle"
6
+ # create the cache directories for sensible.vim:
7
+ # TODO: Support Windows
8
+ if RUBY_PLATFORM =~ /darwin/
9
+ mkdir_p "~/Library/Vim/swap"
10
+ mkdir_p "~/Library/Vim/backup"
11
+ mkdir_p "~/Library/Vim/undo"
12
+ else
13
+ mkdir_p "~/.local/share/vim/swap"
14
+ mkdir_p "~/.local/share/vim/backup"
15
+ mkdir_p "~/.local/share/vim/undo"
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,28 @@
1
+ module Infect
2
+ # Globals be global
3
+ VIMHOME = ENV['VIM'] || "#{ENV['HOME']}/.vim"
4
+ VIMRC = ENV['MYVIMRC'] || "#{ENV['HOME']}/.vimrc"
5
+ BUNDLE_DIR = "#{VIMHOME}/bundle"
6
+
7
+ class Runner
8
+ def self.call(*args)
9
+ force = args.include? "-f"
10
+
11
+ commands = [Command::Prereqs.new()]
12
+
13
+ File.open( VIMRC ).each do |line|
14
+ if line =~ /^"=/
15
+ command, *args = line.split
16
+ commands << Command.build(command.gsub('"=', ''), args)
17
+ end
18
+ end
19
+
20
+ commands.compact.each do |command|
21
+ command.call
22
+ end
23
+
24
+ Cleanup.new(commands, :force => force).call
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,58 @@
1
+ module Infect
2
+ # Inspired by https://github.com/defunkt/hub/blob/master/lib/hub/standalone.rb
3
+ module Standalone
4
+ extend self
5
+
6
+ ROOT = File.expand_path('../../..', __FILE__)
7
+
8
+ PREAMBLE = <<-preamble
9
+ #
10
+ # This file is generated code. DO NOT send patches for it.
11
+ #
12
+ # Original source files with comments are at:
13
+ # https://github.com/csexton/infect
14
+ #
15
+
16
+ preamble
17
+
18
+ def save(filename, path = '.')
19
+ target = File.join(File.expand_path(path), filename)
20
+ File.open(target, 'w') do |f|
21
+ build f
22
+ f.chmod 0755
23
+ end
24
+ end
25
+
26
+ def build io
27
+ io.puts "#!#{ruby_executable}"
28
+ io << PREAMBLE
29
+
30
+ each_source_file do |filename|
31
+ File.open(filename, 'r') do |source|
32
+ source.each_line {|line| io << line if line !~ /^\s*#/ }
33
+ end
34
+ io.puts ''
35
+ end
36
+
37
+ io.puts "Infect::Runner.call(*ARGV)"
38
+ end
39
+
40
+ def each_source_file
41
+ File.open(File.join(ROOT, 'lib/infect.rb'), 'r') do |main|
42
+ main.each_line do |req|
43
+ if req =~ /^require\s+["'](.+)["']/
44
+ yield File.join(ROOT, 'lib', "#{$1}.rb")
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ def ruby_executable
51
+ if File.executable? '/usr/bin/ruby' then '/usr/bin/ruby'
52
+ else
53
+ require 'rbconfig'
54
+ File.join RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']
55
+ end
56
+ end
57
+ end
58
+ end
@@ -1,3 +1,3 @@
1
1
  module Infect
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,7 @@
1
+ require "./lib/infect"
2
+
3
+ describe Infect::Standalone do
4
+ debugger
5
+ binding.pry
6
+
7
+ end
@@ -0,0 +1,220 @@
1
+ #!/usr/bin/ruby
2
+ #
3
+ # This file is generated code. DO NOT send patches for it.
4
+ #
5
+ # Original source files with comments are at:
6
+ # https://github.com/csexton/infect
7
+ #
8
+
9
+ module Infect
10
+ VERSION = "0.0.3"
11
+ end
12
+
13
+ require 'open-uri'
14
+ require 'fileutils'
15
+
16
+ module Infect
17
+ module Colorize
18
+ def colorize(code, str)
19
+ "\e[#{code}m#{str}\e[0m"
20
+ end
21
+ def notice(str)
22
+ puts colorize(32, str)
23
+ end
24
+ def error(str)
25
+ puts colorize(31, str)
26
+ end
27
+ end
28
+ end
29
+
30
+
31
+ require 'open-uri'
32
+ require 'fileutils'
33
+
34
+ module Infect
35
+ class Command
36
+ include Infect::Colorize
37
+
38
+ def self.build(command, args)
39
+ case command.to_sym
40
+ when :bundle
41
+ Bundle.new(args)
42
+ else
43
+ $stderr.puts "WARNING: #{command} is not a valid command, ignorning"
44
+ end
45
+ end
46
+
47
+ protected
48
+
49
+ def mkdir(path)
50
+ expanded_path = File.expand_path(path)
51
+ unless File.directory?(expanded_path)
52
+ notice "Making dir #{path}"
53
+ FileUtils.mkdir_p(expanded_path)
54
+ end
55
+ end
56
+
57
+ def chdir(path)
58
+ Dir.chdir(path)
59
+ end
60
+
61
+ def download(url, path)
62
+ File.open(File.expand_path(path), "w") do |file|
63
+ open(url) do |read_file|
64
+ file.write(read_file.read)
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ module Infect
72
+ class Command
73
+ class Bundle < Command
74
+ attr_reader :bundle, :name, :location
75
+ def initialize(args)
76
+ @bundle = args[0]
77
+ @name = File.basename(bundle)
78
+ @location = File.expand_path("#{BUNDLE_DIR}/#{name}")
79
+ end
80
+
81
+ def url
82
+ "git@github.com:#{bundle}.git"
83
+ end
84
+
85
+ def install
86
+ notice "Installing #{name}... "
87
+ mkdir BUNDLE_DIR
88
+ chdir BUNDLE_DIR
89
+ git "clone '#{url}'"
90
+ end
91
+
92
+ def update
93
+ notice "Updating #{name}... "
94
+ chdir @location
95
+ git "pull"
96
+ end
97
+
98
+ def call
99
+ if File.exists? @location
100
+ update
101
+ else
102
+ install
103
+ end
104
+ end
105
+
106
+ private
107
+
108
+ def git(args)
109
+ `git #{args}`
110
+ end
111
+ end
112
+ end
113
+ end
114
+
115
+ module Infect
116
+ class Command
117
+ class Prereqs < Command
118
+ def call
119
+ mkdir_p "~/.vim/bundle"
120
+ if RUBY_PLATFORM =~ /darwin/
121
+ mkdir_p "~/Library/Vim/swap"
122
+ mkdir_p "~/Library/Vim/backup"
123
+ mkdir_p "~/Library/Vim/undo"
124
+ else
125
+ mkdir_p "~/.local/share/vim/swap"
126
+ mkdir_p "~/.local/share/vim/backup"
127
+ mkdir_p "~/.local/share/vim/undo"
128
+ end
129
+ end
130
+ end
131
+ end
132
+ end
133
+
134
+ module Infect
135
+ class Cleanup
136
+ include Infect::Colorize
137
+ attr_reader :commands, :force
138
+
139
+ def initialize(commands, args = {})
140
+ @commands = commands
141
+ @force = args[:force] || false
142
+ end
143
+
144
+ def call
145
+ uninstall_unless_included names
146
+ end
147
+
148
+ private
149
+
150
+ def uninstall_unless_included(list)
151
+ Dir["#{BUNDLE_DIR}/*"].each do |path|
152
+ unless list.include? File.basename(path)
153
+ if confirm(path)
154
+ notice "Deleting #{path}"
155
+ require 'fileutils'
156
+ FileUtils.rm_rf path
157
+ else
158
+ notice "Leaving #{path}"
159
+ end
160
+ end
161
+ end
162
+ end
163
+
164
+ def confirm(name)
165
+ unless force
166
+ print "Remove #{name}? [Yn]: "
167
+ response = STDIN.gets.chomp
168
+ case response.downcase
169
+ when ''
170
+ true
171
+ when 'y'
172
+ true
173
+ else
174
+ false
175
+ end
176
+ end
177
+ end
178
+
179
+ def names
180
+ list = []
181
+ commands.each do |command|
182
+ if command.respond_to? :name
183
+ list << command.name
184
+ end
185
+ end
186
+ list
187
+ end
188
+
189
+ end
190
+ end
191
+
192
+ module Infect
193
+ VIMHOME = ENV['VIM'] || "#{ENV['HOME']}/.vim"
194
+ VIMRC = ENV['MYVIMRC'] || "#{ENV['HOME']}/.vimrc"
195
+ BUNDLE_DIR = "#{VIMHOME}/bundle"
196
+
197
+ class Runner
198
+ def self.call(*args)
199
+ force = args.include? "-f"
200
+
201
+ commands = [Command::Prereqs.new()]
202
+
203
+ File.open( VIMRC ).each do |line|
204
+ if line =~ /^"=/
205
+ command, *args = line.split
206
+ commands << Command.build(command.gsub('"=', ''), args)
207
+ end
208
+ end
209
+
210
+ commands.compact.each do |command|
211
+ command.call
212
+ end
213
+
214
+ Cleanup.new(commands, :force => force).call
215
+
216
+ end
217
+ end
218
+ end
219
+
220
+ Infect::Runner.call(*ARGV)
metadata CHANGED
@@ -1,32 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infect
3
3
  version: !ruby/object:Gem::Version
4
+ version: 0.0.3
4
5
  prerelease:
5
- version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Christopher Sexton
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-14 00:00:00.000000000 Z
12
+ date: 2013-03-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- version_requirements: !ruby/object:Gem::Requirement
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ! '>='
18
20
  - !ruby/object:Gem::Version
19
21
  version: '0'
20
- none: false
21
- name: rspec
22
22
  type: :development
23
23
  prerelease: false
24
- requirement: !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
25
26
  requirements:
26
27
  - - ! '>='
27
28
  - !ruby/object:Gem::Version
28
29
  version: '0'
29
- none: false
30
30
  description: Asset Pipeline for Pathogen.vim
31
31
  email:
32
32
  - csexton@gmail.com
@@ -45,10 +45,17 @@ files:
45
45
  - bin/infect
46
46
  - infect.gemspec
47
47
  - lib/infect.rb
48
+ - lib/infect/cleanup.rb
49
+ - lib/infect/colorize.rb
48
50
  - lib/infect/command.rb
49
51
  - lib/infect/command/bundle.rb
52
+ - lib/infect/command/prereqs.rb
53
+ - lib/infect/runner.rb
54
+ - lib/infect/standalone.rb
50
55
  - lib/infect/version.rb
51
56
  - spec/command_spec.rb
57
+ - spec/standalone_spec.rb
58
+ - standalone/infect
52
59
  homepage: https://github.com/csexton/infect
53
60
  licenses: []
54
61
  post_install_message:
@@ -56,23 +63,24 @@ rdoc_options: []
56
63
  require_paths:
57
64
  - lib
58
65
  required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
59
67
  requirements:
60
68
  - - ! '>='
61
69
  - !ruby/object:Gem::Version
62
70
  version: '0'
63
- none: false
64
71
  required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
65
73
  requirements:
66
74
  - - ! '>='
67
75
  - !ruby/object:Gem::Version
68
76
  version: '0'
69
- none: false
70
77
  requirements: []
71
78
  rubyforge_project:
72
- rubygems_version: 1.8.24
79
+ rubygems_version: 1.8.25
73
80
  signing_key:
74
81
  specification_version: 3
75
82
  summary: Asset Pipeline for Vim and Pathogen, install vim bundles included in your
76
83
  vimrc
77
84
  test_files:
78
85
  - spec/command_spec.rb
86
+ - spec/standalone_spec.rb