gitenv 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -12,6 +12,7 @@ group :development do
12
12
  gem 'bundler'
13
13
  gem 'rake'
14
14
  gem 'rspec'
15
+ gem 'fakefs', '~> 0.4.2', :require => 'fakefs/safe'
15
16
  gem 'jeweler'
16
17
  gem 'gemcutter'
17
18
  gem 'gem-release'
data/README.md CHANGED
@@ -10,9 +10,9 @@ Run gitenv without arguments to check the symlink configuration. First-time user
10
10
  ~/.gitconfig -> ~/projects/env/.gitconfig not yet set up
11
11
  ~/.zshrc -> ~/projects/env/.zshrc not yet set up
12
12
 
13
- Then run it with **update** to set up the missing symlinks.
13
+ Then run it with **apply** to set up the missing symlinks.
14
14
 
15
- #=> gitenv update
15
+ #=> gitenv apply
16
16
 
17
17
  ~/.gemrc -> ~/projects/env/.gemrc ok
18
18
  ~/.gitconfig -> ~/projects/env/.gitconfig ok
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.1.0
@@ -2,9 +2,7 @@
2
2
  require 'paint'
3
3
 
4
4
  module Gitenv
5
- VERSION = '0.0.5'
5
+ VERSION = '0.1.0'
6
6
  end
7
7
 
8
- [ :context, :config, :controller, :symlink, :copy, :enumerator, :action ].each do |lib|
9
- require File.join(File.dirname(__FILE__), 'gitenv', lib.to_s)
10
- end
8
+ Dir[File.join File.dirname(__FILE__), File.basename(__FILE__, '.*'), '*.rb'].each{ |lib| require lib }
@@ -0,0 +1,32 @@
1
+
2
+ module Gitenv
3
+
4
+ class Action
5
+ attr_reader :options
6
+
7
+ def initialize context, type, files, options
8
+ @context, @type, @files, @options = context, type, files, options
9
+ end
10
+
11
+ def each &block
12
+ @files.files(@context.from).each do |f|
13
+ block.call @type.new(@context, f, @options)
14
+ end
15
+ end
16
+
17
+ def each_file &block
18
+ @files.files(@context.from).each do |f|
19
+ block.call File.join(@context.from, f)
20
+ end
21
+ end
22
+
23
+ %w(from to).each do |m|
24
+ define_method m do |*args|
25
+ @context.send *(args.unshift m)
26
+ self
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ Dir[File.join File.dirname(__FILE__), File.basename(__FILE__, '.*'), '*.rb'].each{ |lib| require lib }
@@ -0,0 +1,86 @@
1
+ # encoding: UTF-8
2
+ require 'fileutils'
3
+ require 'digest/sha1'
4
+
5
+ module Gitenv
6
+
7
+ class Copy
8
+
9
+ class Action < Action
10
+
11
+ def initialize context, files, options
12
+ super context, Copy, files, options
13
+ end
14
+
15
+ def overwrite *args
16
+ options = args.last.kind_of?(Hash) ? args.pop : {}
17
+ overwrite = args.empty? ? true : args.shift
18
+ @options[:overwrite] = overwrite
19
+ @options[:backup] = options[:backup] if options.key?(:backup)
20
+ self
21
+ end
22
+
23
+ def once
24
+ @options[:overwrite] = false
25
+ @options[:backup] = false
26
+ self
27
+ end
28
+ end
29
+
30
+ def initialize context, file, options = {}
31
+ @context, @file = context, file
32
+ @as, @overwrite, @backup = options[:as], options[:overwrite], options[:backup]
33
+ @backup = true if @overwrite and !options.key?(:backup)
34
+ end
35
+
36
+ def apply
37
+ backup_exists = File.exists? target_backup
38
+ FileUtils.mv target, target_backup if @backup and File.exists?(target) and !backup_exists
39
+ FileUtils.rm target if @overwrite and File.exists?(target) and !backup_exists
40
+ FileUtils.cp origin, target unless File.exists?(target)
41
+ end
42
+
43
+ def to_s
44
+ "#{Paint[target, :cyan]} #{Paint['<', :bold]} #{origin}"
45
+ end
46
+
47
+ def status
48
+ if !File.exists?(target)
49
+ Status.missing "is not set up; apply will create the copy"
50
+ elsif @overwrite == false or digest(origin) == digest(target)
51
+ Status.ok 'ok'
52
+ elsif !@overwrite
53
+ Status.error "already exists; enable overwrite if you want to replace it"
54
+ elsif @backup and File.exists?(target_backup)
55
+ Status.error "already exists with backup copy"
56
+ else
57
+ backup_notice = if @backup; " backup the file and"; end
58
+ Status.warning "already exists; apply will#{backup_notice} overwrite"
59
+ end
60
+ end
61
+
62
+ def origin
63
+ @origin ||= File.join(*[ @context.from, @file ].compact)
64
+ end
65
+
66
+ def target
67
+ @target ||= File.join(*[ @context.to, target_name].compact)
68
+ end
69
+
70
+ def target_backup
71
+ @target_backup ||= "#{target}.orig"
72
+ end
73
+
74
+ private
75
+
76
+ def target_name
77
+ @target_name ||= @as || @file
78
+ end
79
+
80
+ def digest file
81
+ Digest::SHA1.new.tap do |dig|
82
+ File.open(file, 'rb'){ |io| dig.update io.readpartial(4096) while !io.eof }
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,69 @@
1
+ # encoding: UTF-8
2
+
3
+ module Gitenv
4
+
5
+ class Symlink
6
+
7
+ class Action < Action
8
+
9
+ def initialize context, files, options
10
+ super context, Symlink, files, options
11
+ end
12
+
13
+ def overwrite overwrite = true
14
+ @options[:overwrite] = overwrite
15
+ self
16
+ end
17
+
18
+ def once
19
+ @options[:overwrite] = false
20
+ self
21
+ end
22
+ end
23
+
24
+ def initialize context, file, options = {}
25
+ @context, @file = context, file
26
+ @as, @overwrite = options[:as], options[:overwrite]
27
+ end
28
+
29
+ def apply
30
+ FileUtils.rm link if @overwrite and File.symlink?(link) # FIXME: only if link points somewhere else
31
+ File.symlink target, link unless File.symlink?(link) or File.exists?(link)
32
+ end
33
+
34
+ def to_s
35
+ "#{Paint[link, :cyan]} #{Paint['->', :bold]} #{target}"
36
+ end
37
+
38
+ def status
39
+ if File.symlink? link
40
+ current_target = File.expand_path File.readlink(link)
41
+ if @overwrite == false or current_target == target
42
+ Status.ok 'ok'
43
+ elsif !@overwrite
44
+ Status.error "exists but points to #{current_target}; enable overwrite if you want to replace it"
45
+ else
46
+ Status.warning "currently points to #{current_target}; apply will overwrite"
47
+ end
48
+ elsif File.exists? link
49
+ Status.error "exists but is not a symlink; apply will ignore"
50
+ else
51
+ Status.missing "is not set up; apply will create the link"
52
+ end
53
+ end
54
+
55
+ def link
56
+ @link ||= File.join(*[ @context.to, link_name].compact)
57
+ end
58
+
59
+ def target
60
+ @target ||= File.join(*[ @context.from, @file ].compact)
61
+ end
62
+
63
+ private
64
+
65
+ def link_name
66
+ @link_name ||= @as || @file
67
+ end
68
+ end
69
+ end
@@ -1,47 +1,64 @@
1
+ require 'rbconfig'
1
2
 
2
3
  module Gitenv
3
4
 
4
5
  class Config
5
- include Context
6
6
 
7
+ attr_reader :repos
7
8
  attr_reader :actions
8
- attr_accessor :repository
9
- attr_reader :home
10
9
 
11
- def initialize home
12
- @home = home
13
- @actions = []
10
+ def initialize
11
+ @context = Context.new self
12
+ @repos, @actions = [], []
14
13
  end
15
14
 
16
- def repo path
17
- @repository = File.expand_path path
15
+ def repo path, &block
16
+ @repos << Repository.new(path)
17
+ @context.from path, &block
18
+ self
18
19
  end
19
20
 
20
21
  def symlink file, options = {}
21
- Action.new(self, Symlink, enumerator(file), options).tap{ |a| @actions << a }
22
+ raise "You must specify a repository or a source directory to symlink from" unless @context.from
23
+ Symlink::Action.new(@context.dup, matcher(file), options).tap{ |a| @actions << a }
22
24
  end
23
25
 
24
26
  def copy file, options = {}
25
- Action.new(self, Copy, enumerator(file), options).tap{ |a| @actions << a }
27
+ raise "You must specify a repository or a source directory to copy from" unless @context.from
28
+ Copy::Action.new(@context.dup, matcher(file), options).tap{ |a| @actions << a }
26
29
  end
27
30
 
28
- def all_files
29
- :all_files
31
+ def all_files options = {}
32
+ matcher :all_files, options
30
33
  end
31
34
 
32
- def dot_files
33
- :dot_files
35
+ def dot_files options = {}
36
+ matcher :dot_files, options
37
+ end
38
+
39
+ %w(from to).each do |m|
40
+ define_method m do |*args,&block|
41
+ @context.send *(args.unshift m), &block
42
+ self
43
+ end
44
+ end
45
+
46
+ def ignores
47
+ @context.ignores
34
48
  end
35
49
 
36
50
  private
37
51
 
38
- def enumerator file
39
- if file == :all_files
40
- AllFiles.new
52
+ def matcher file, options = {}
53
+ options[:ignores] ||= @context.ignores.dup
54
+ if file.kind_of? FilesMatcher
55
+ file
56
+ elsif file == :all_files
57
+ AllFiles.new options
41
58
  elsif file == :dot_files
42
- DotFiles.new
59
+ DotFiles.new options
43
60
  else
44
- OneFile.new file
61
+ OneFile.new file, options
45
62
  end
46
63
  end
47
64
  end
@@ -1,60 +1,49 @@
1
+ require 'rbconfig'
1
2
 
2
3
  module Gitenv
3
4
 
4
- module Context
5
- attr_accessor :from_paths, :to_paths, :absolute
5
+ class Context
6
+ attr_accessor :ignores
6
7
 
7
- def from path, &block
8
- (@from_paths ||= []) << path
9
- if block
10
- instance_eval &block
11
- @from_paths.pop
12
- end
13
- self
14
- end
8
+ def initialize config, options = {}
9
+ @config, @from, @ignores = config, options[:from], options[:ignores]
15
10
 
16
- def from_path
17
- @from_paths ? File.join(*([ @config.repository, @from_paths ].flatten)) : @config.repository
18
- end
11
+ @to ||= File.expand_path('~')
19
12
 
20
- def to path, &block
21
- (@to_paths ||= []) << path
22
- if block
23
- instance_eval &block
24
- @to_paths.pop
25
- end
26
- self
13
+ @ignores = options[:ignores] || []
14
+ @ignores << '.DS_Store' if @ignores.empty? and RbConfig::CONFIG['host_os'] =~ /darwin/
27
15
  end
28
16
 
29
- def to_abs path, &block
30
- previous = @to_paths
31
- @to_paths = [ path ]
32
- @absolute = true
17
+ def from path = nil, &block
18
+ return @from if path.nil?
19
+
20
+ old = @from
21
+ @from = @from ? File.expand_path(path, @from) : File.expand_path(path)
22
+
33
23
  if block
34
- instance_eval &block
35
- @to_paths = previous
36
- @absolute = false
24
+ @config.instance_eval &block
25
+ @from = old
37
26
  end
27
+
38
28
  self
39
29
  end
40
30
 
41
- def to_path
42
- @to_paths ? File.join(*(@absolute ? @to_paths : [ @config.home, @to_paths ]).flatten) : @config.home
43
- end
31
+ def to path = nil, &block
32
+ return @to if path.nil?
44
33
 
45
- def copy! config
46
- self.from_paths = config.from_paths ? config.from_paths.dup : []
47
- self.to_paths = config.to_paths ? config.to_paths.dup : []
48
- self.absolute = config.absolute
49
- @config = config
50
- end
34
+ old = @to
35
+ @to = @to ? File.expand_path(path, @to) : File.expand_path(path)
51
36
 
52
- def home
53
- @config.home
37
+ if block
38
+ @config.instance_eval &block
39
+ @to = old
40
+ end
41
+
42
+ self
54
43
  end
55
44
 
56
- def repository
57
- @config.repository
45
+ def dup
46
+ Context.new @config, from: @from, to: @to, ignores: @ignores.dup
58
47
  end
59
48
  end
60
49
  end
@@ -9,8 +9,7 @@ module Gitenv
9
9
  @action = action
10
10
  @options = options
11
11
 
12
- @home = File.expand_path '~'
13
- @config = Config.new @home
12
+ @config = Config.new
14
13
  end
15
14
 
16
15
  def run
@@ -23,23 +22,21 @@ module Gitenv
23
22
 
24
23
  load_config_file!
25
24
 
26
- @config.repository = repository
27
- check_repository!
25
+ #@config.from repository
26
+ #check_repository!
28
27
 
29
28
  # load dot files by default
30
- if @config.actions.empty?
31
- @config.symlink @config.dot_files
32
- end
33
-
34
- check_files!
29
+ #if @config.actions.empty?
30
+ # @config.symlink @config.dot_files
31
+ #end
35
32
 
36
- longest = 0
37
- @config.actions.each{ |a| a.each{ |impl| longest = impl.description.length if impl.description.length > longest } }
33
+ #check_files!
38
34
 
35
+ renderer = Renderer.new
39
36
  @config.actions.each do |a|
40
- a.each :justify => longest + 3 do |impl|
41
- impl.update! if @action == :update
42
- puts impl
37
+ a.each do |impl|
38
+ impl.apply if @action == :apply
39
+ puts renderer.render(impl)
43
40
  end
44
41
  end
45
42
  end
@@ -88,7 +85,7 @@ module Gitenv
88
85
  end
89
86
 
90
87
  def repository
91
- @options.repo || @config.repository || ENV['GITENV_REPO']
88
+ @options.repo || @config.from || ENV['GITENV_REPO']
92
89
  end
93
90
 
94
91
  def config_file
@@ -97,7 +94,7 @@ module Gitenv
97
94
  elsif ENV['GITENV_CONFIG']
98
95
  File.expand_path ENV['GITENV_CONFIG']
99
96
  else
100
- File.join @home, '.gitenv.rb'
97
+ File.expand_path '~/.gitenv.rb'
101
98
  end
102
99
  end
103
100
 
@@ -114,8 +111,8 @@ module Gitenv
114
111
  a.each_file do |f|
115
112
  if !File.exists?(f)
116
113
  problems << { :file => f, :msg => "does not exist" }
117
- elsif !File.file?(f)
118
- problems << { :file => f, :msg => "is not a file" }
114
+ #elsif !File.file?(f)
115
+ # problems << { :file => f, :msg => "is not a file" }
119
116
  elsif !File.readable?(f)
120
117
  problems << { :file => f, :msg => "is not readable" }
121
118
  end
@@ -142,21 +139,21 @@ module Gitenv
142
139
  end
143
140
 
144
141
  def check_repository!
145
- if !@config.repository
142
+ if !@config.from
146
143
  msg = "You have not specified an environment repository."
147
144
  msg << "\nYou must either use the -r, --repo option or create"
148
145
  msg << "\na configuration file (~/.gitenv.rb by default) with"
149
146
  msg << "\nthe repo setting."
150
147
  abort msg
151
148
  end
152
- return if File.directory? @config.repository
153
- notice = File.exists?(@config.repository) ? 'is not a directory' : 'does not exist'
149
+ return if File.directory? @config.from
150
+ notice = File.exists?(@config.from) ? 'is not a directory' : 'does not exist'
154
151
  from = if @options.repo
155
152
  "--repo #{@options.repo}"
156
153
  elsif ENV['GITENV_REPO']
157
154
  "$GITENV_REPO = #{ENV['GITENV_REPO']}"
158
155
  else
159
- %/repo "#{@config.repository}"/
156
+ %/repo "#{@config.from}"/
160
157
  end
161
158
  abort "The repository you have specified #{notice}.\n (#{from})"
162
159
  end
@@ -0,0 +1,3 @@
1
+ [ :matcher, :all_files, :dot_files, :one_file ].each do |lib|
2
+ require File.join(File.dirname(__FILE__), 'files', lib.to_s)
3
+ end
@@ -0,0 +1,16 @@
1
+
2
+ module Gitenv
3
+
4
+ class AllFiles < FilesMatcher
5
+
6
+ def files path
7
+ filter path, super(path)
8
+ end
9
+
10
+ private
11
+
12
+ def filter path, entries
13
+ entries.select{ |e| File.file? File.join(path, e) }
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,26 @@
1
+
2
+ module Gitenv
3
+
4
+ class FilesMatcher
5
+
6
+ def initialize options = {}
7
+ @options = options
8
+ @ignores = options[:ignores] ? [ options[:ignores] ].flatten : []
9
+ end
10
+
11
+ def files path
12
+ ignore Dir.entries(path)
13
+ end
14
+
15
+ def except *args
16
+ @ignores.concat args
17
+ self
18
+ end
19
+
20
+ private
21
+
22
+ def ignore entries
23
+ entries.reject{ |e| @ignores.any?{ |g| g == e or (g.kind_of?(Regexp) and e.match(g)) } }
24
+ end
25
+ end
26
+ end
@@ -1,9 +1,10 @@
1
1
 
2
2
  module Gitenv
3
3
 
4
- class OneFile < FileEnumerator
4
+ class OneFile < FilesMatcher
5
5
 
6
- def initialize file
6
+ def initialize file, options = {}
7
+ super options
7
8
  @file = file
8
9
  end
9
10
 
@@ -0,0 +1,21 @@
1
+
2
+ module Gitenv
3
+
4
+ class Renderer
5
+
6
+ def initialize options = {}
7
+ @options = options
8
+ end
9
+
10
+ def render action
11
+
12
+ status = action.status
13
+ color = status.color
14
+ error = if !status.ok?
15
+ "\n #{Paint[status.message, color]}"
16
+ end
17
+
18
+ " #{Paint[status.marker, color]} #{action}#{error}"
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,10 @@
1
+
2
+ module Gitenv
3
+
4
+ class Repository
5
+
6
+ def initialize path
7
+ @path = path
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,39 @@
1
+ # encoding: UTF-8
2
+
3
+ module Gitenv
4
+
5
+ class Status
6
+ TYPES = [ :ok, :missing, :warning, :error ]
7
+ COLORS = { ok: :green, missing: :blue, warning: :yellow, error: :red }
8
+
9
+ attr_reader :type, :message
10
+
11
+ class << self
12
+ TYPES.each do |m|
13
+ define_method m do |message|
14
+ self.new m, message
15
+ end
16
+ end
17
+ end
18
+
19
+ TYPES.each do |m|
20
+ define_method "#{m}?" do
21
+ @type == m
22
+ end
23
+ end
24
+
25
+ def marker
26
+ @type == :ok ? "✓" : "✗"
27
+ end
28
+
29
+ def color
30
+ COLORS[@type]
31
+ end
32
+
33
+ private
34
+
35
+ def initialize type, message
36
+ @type, @message = type, message
37
+ end
38
+ end
39
+ end
@@ -16,11 +16,11 @@ command :info do |c|
16
16
  end
17
17
  end
18
18
 
19
- command :update do |c|
20
- c.syntax = 'gitenv update'
19
+ command :apply do |c|
20
+ c.syntax = 'gitenv apply'
21
21
  c.description = 'Create/update the symlinks'
22
22
  c.action do |args,options|
23
- Gitenv::Controller.new(:update, options).run
23
+ Gitenv::Controller.new(:apply, options).run
24
24
  end
25
25
  end
26
26
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitenv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
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: 2012-09-24 00:00:00.000000000 Z
12
+ date: 2013-05-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: paint
@@ -91,6 +91,22 @@ dependencies:
91
91
  - - ! '>='
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: fakefs
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 0.4.2
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 0.4.2
94
110
  - !ruby/object:Gem::Dependency
95
111
  name: jeweler
96
112
  requirement: !ruby/object:Gem::Requirement
@@ -180,33 +196,27 @@ extra_rdoc_files:
180
196
  - LICENSE.txt
181
197
  - README.md
182
198
  files:
183
- - .rspec
184
- - .rvmrc
185
- - .screenrc
186
- - .travis.yml
187
199
  - Gemfile
188
- - Gemfile.lock
189
200
  - LICENSE.txt
190
201
  - README.md
191
- - Rakefile
192
202
  - VERSION
193
203
  - bin/gitenv
194
- - gitenv.gemspec
195
204
  - lib/gitenv.rb
196
- - lib/gitenv/action.rb
205
+ - lib/gitenv/actions.rb
206
+ - lib/gitenv/actions/copy.rb
207
+ - lib/gitenv/actions/symlink.rb
197
208
  - lib/gitenv/config.rb
198
209
  - lib/gitenv/context.rb
199
210
  - lib/gitenv/controller.rb
200
- - lib/gitenv/copy.rb
201
- - lib/gitenv/enumerator.rb
202
- - lib/gitenv/enumerator/all_files.rb
203
- - lib/gitenv/enumerator/dot_files.rb
204
- - lib/gitenv/enumerator/enumerator.rb
205
- - lib/gitenv/enumerator/one_file.rb
206
- - lib/gitenv/symlink.rb
211
+ - lib/gitenv/files.rb
212
+ - lib/gitenv/files/all_files.rb
213
+ - lib/gitenv/files/dot_files.rb
214
+ - lib/gitenv/files/matcher.rb
215
+ - lib/gitenv/files/one_file.rb
216
+ - lib/gitenv/renderer.rb
217
+ - lib/gitenv/repository.rb
218
+ - lib/gitenv/status.rb
207
219
  - lib/program.rb
208
- - spec/helper.rb
209
- - spec/version_spec.rb
210
220
  homepage: http://github.com/AlphaHydrae/gitenv
211
221
  licenses:
212
222
  - MIT
@@ -228,8 +238,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
228
238
  version: '0'
229
239
  requirements: []
230
240
  rubyforge_project:
231
- rubygems_version: 1.8.24
241
+ rubygems_version: 1.8.25
232
242
  signing_key:
233
243
  specification_version: 3
234
244
  summary: Symlink manager for git repositories with configuration files.
235
245
  test_files: []
246
+ has_rdoc:
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --format doc
data/.rvmrc DELETED
@@ -1,52 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
- # development environment upon cd'ing into the directory
5
-
6
- # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
- # Only full ruby name is supported here, for short names use:
8
- # echo "rvm use 1.9.3" > .rvmrc
9
- environment_id="ruby-1.9.3-p194@gitenv"
10
-
11
- # Uncomment the following lines if you want to verify rvm version per project
12
- # rvmrc_rvm_version="1.15.8 ()" # 1.10.1 seams as a safe start
13
- # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
- # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
- # return 1
16
- # }
17
-
18
- # First we attempt to load the desired environment directly from the environment
19
- # file. This is very fast and efficient compared to running through the entire
20
- # CLI and selector. If you want feedback on which environment was used then
21
- # insert the word 'use' after --create as this triggers verbose mode.
22
- if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
- && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
- then
25
- \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
- [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
27
- \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
28
- if [[ $- == *i* ]] # check for interactive shells
29
- then echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
30
- else echo "Using: $GEM_HOME" # don't use colors in non-interactive shells
31
- fi
32
- else
33
- # If the environment file has not yet been created, use the RVM CLI to select.
34
- rvm --create use "$environment_id" || {
35
- echo "Failed to create RVM environment '${environment_id}'."
36
- return 1
37
- }
38
- fi
39
-
40
- # If you use bundler, this might be useful to you:
41
- # if [[ -s Gemfile ]] && {
42
- # ! builtin command -v bundle >/dev/null ||
43
- # builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
44
- # }
45
- # then
46
- # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
47
- # gem install bundler
48
- # fi
49
- # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
50
- # then
51
- # bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
52
- # fi
data/.screenrc DELETED
@@ -1,7 +0,0 @@
1
- source $HOME/.screenrc
2
-
3
- screen -t vim 0 $EDITOR -c GG
4
- screen -t zsh 1
5
- screen -t spec 2
6
- stuff "rake"
7
- select vim
@@ -1,5 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.8.7
4
- - 1.9.2
5
- - 1.9.3
@@ -1,50 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- commander (4.1.2)
5
- highline (~> 1.6.11)
6
- diff-lcs (1.1.3)
7
- gem-release (0.4.1)
8
- gemcutter (0.7.1)
9
- git (1.2.5)
10
- highline (1.6.15)
11
- jeweler (1.8.4)
12
- bundler (~> 1.0)
13
- git (>= 1.2.5)
14
- rake
15
- rdoc
16
- json (1.7.5)
17
- multi_json (1.3.6)
18
- paint (0.8.5)
19
- rake (0.9.2.2)
20
- rake-version (0.3.0)
21
- rake (~> 0.9.2)
22
- rdoc (3.12)
23
- json (~> 1.4)
24
- rspec (2.11.0)
25
- rspec-core (~> 2.11.0)
26
- rspec-expectations (~> 2.11.0)
27
- rspec-mocks (~> 2.11.0)
28
- rspec-core (2.11.1)
29
- rspec-expectations (2.11.3)
30
- diff-lcs (~> 1.1.3)
31
- rspec-mocks (2.11.3)
32
- simplecov (0.6.4)
33
- multi_json (~> 1.0)
34
- simplecov-html (~> 0.5.3)
35
- simplecov-html (0.5.3)
36
-
37
- PLATFORMS
38
- ruby
39
-
40
- DEPENDENCIES
41
- bundler
42
- commander (~> 4.1.2)
43
- gem-release
44
- gemcutter
45
- jeweler
46
- paint (~> 0.8.5)
47
- rake
48
- rake-version
49
- rspec
50
- simplecov
data/Rakefile DELETED
@@ -1,51 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'rubygems'
4
- require 'bundler'
5
- begin
6
- Bundler.setup(:default, :development)
7
- rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts "Run `bundle install` to install missing gems"
10
- exit e.status_code
11
- end
12
- require 'rake'
13
-
14
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
- gem.name = "gitenv"
18
- gem.homepage = "http://github.com/AlphaHydrae/gitenv"
19
- gem.license = "MIT"
20
- gem.summary = %Q{Symlink manager for git repositories with configuration files.}
21
- gem.description = %Q{Gitenv sets up symlinks to your configuration files in a git repository.}
22
- gem.email = "hydrae.alpha@gmail.com"
23
- gem.authors = ["AlphaHydrae"]
24
- # dependencies defined in Gemfile
25
- end
26
- Jeweler::RubygemsDotOrgTasks.new
27
-
28
- Rake::TaskManager.class_eval do
29
- def remove_task(task_name)
30
- @tasks.delete(task_name.to_s)
31
- end
32
- end
33
-
34
- [ 'version', 'version:bump:major', 'version:bump:minor', 'version:bump:patch', 'version:write' ].each do |task|
35
- Rake.application.remove_task task
36
- end
37
-
38
- # version tasks
39
- require 'rake-version'
40
- RakeVersion::Tasks.new do |v|
41
- v.copy 'lib/gitenv.rb'
42
- end
43
-
44
- require 'rspec/core/rake_task'
45
- desc "Run specs"
46
- RSpec::Core::RakeTask.new do |t|
47
- #t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
48
- # Put spec opts in a file named .rspec in root
49
- end
50
-
51
- task :default => :spec
@@ -1,94 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = "gitenv"
8
- s.version = "0.0.5"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["AlphaHydrae"]
12
- s.date = "2012-09-24"
13
- s.description = "Gitenv sets up symlinks to your configuration files in a git repository."
14
- s.email = "hydrae.alpha@gmail.com"
15
- s.executables = ["gitenv"]
16
- s.extra_rdoc_files = [
17
- "LICENSE.txt",
18
- "README.md"
19
- ]
20
- s.files = [
21
- ".rspec",
22
- ".rvmrc",
23
- ".screenrc",
24
- ".travis.yml",
25
- "Gemfile",
26
- "Gemfile.lock",
27
- "LICENSE.txt",
28
- "README.md",
29
- "Rakefile",
30
- "VERSION",
31
- "bin/gitenv",
32
- "gitenv.gemspec",
33
- "lib/gitenv.rb",
34
- "lib/gitenv/action.rb",
35
- "lib/gitenv/config.rb",
36
- "lib/gitenv/context.rb",
37
- "lib/gitenv/controller.rb",
38
- "lib/gitenv/copy.rb",
39
- "lib/gitenv/enumerator.rb",
40
- "lib/gitenv/enumerator/all_files.rb",
41
- "lib/gitenv/enumerator/dot_files.rb",
42
- "lib/gitenv/enumerator/enumerator.rb",
43
- "lib/gitenv/enumerator/one_file.rb",
44
- "lib/gitenv/symlink.rb",
45
- "lib/program.rb",
46
- "spec/helper.rb",
47
- "spec/version_spec.rb"
48
- ]
49
- s.homepage = "http://github.com/AlphaHydrae/gitenv"
50
- s.licenses = ["MIT"]
51
- s.require_paths = ["lib"]
52
- s.rubygems_version = "1.8.24"
53
- s.summary = "Symlink manager for git repositories with configuration files."
54
-
55
- if s.respond_to? :specification_version then
56
- s.specification_version = 3
57
-
58
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
59
- s.add_runtime_dependency(%q<paint>, ["~> 0.8.5"])
60
- s.add_runtime_dependency(%q<commander>, ["~> 4.1.2"])
61
- s.add_development_dependency(%q<bundler>, [">= 0"])
62
- s.add_development_dependency(%q<rake>, [">= 0"])
63
- s.add_development_dependency(%q<rspec>, [">= 0"])
64
- s.add_development_dependency(%q<jeweler>, [">= 0"])
65
- s.add_development_dependency(%q<gemcutter>, [">= 0"])
66
- s.add_development_dependency(%q<gem-release>, [">= 0"])
67
- s.add_development_dependency(%q<rake-version>, [">= 0"])
68
- s.add_development_dependency(%q<simplecov>, [">= 0"])
69
- else
70
- s.add_dependency(%q<paint>, ["~> 0.8.5"])
71
- s.add_dependency(%q<commander>, ["~> 4.1.2"])
72
- s.add_dependency(%q<bundler>, [">= 0"])
73
- s.add_dependency(%q<rake>, [">= 0"])
74
- s.add_dependency(%q<rspec>, [">= 0"])
75
- s.add_dependency(%q<jeweler>, [">= 0"])
76
- s.add_dependency(%q<gemcutter>, [">= 0"])
77
- s.add_dependency(%q<gem-release>, [">= 0"])
78
- s.add_dependency(%q<rake-version>, [">= 0"])
79
- s.add_dependency(%q<simplecov>, [">= 0"])
80
- end
81
- else
82
- s.add_dependency(%q<paint>, ["~> 0.8.5"])
83
- s.add_dependency(%q<commander>, ["~> 4.1.2"])
84
- s.add_dependency(%q<bundler>, [">= 0"])
85
- s.add_dependency(%q<rake>, [">= 0"])
86
- s.add_dependency(%q<rspec>, [">= 0"])
87
- s.add_dependency(%q<jeweler>, [">= 0"])
88
- s.add_dependency(%q<gemcutter>, [">= 0"])
89
- s.add_dependency(%q<gem-release>, [">= 0"])
90
- s.add_dependency(%q<rake-version>, [">= 0"])
91
- s.add_dependency(%q<simplecov>, [">= 0"])
92
- end
93
- end
94
-
@@ -1,24 +0,0 @@
1
-
2
- module Gitenv
3
-
4
- class Action
5
- include Context
6
-
7
- def initialize config, type, files, options
8
- @type, @files, @options = type, files, options
9
- copy! config
10
- end
11
-
12
- def each options = {}, &block
13
- @files.each from_path do |f|
14
- block.call @type.new(self, f, @options.merge(options))
15
- end
16
- end
17
-
18
- def each_file &block
19
- @files.each from_path do |f|
20
- block.call File.join(from_path, f)
21
- end
22
- end
23
- end
24
- end
@@ -1,68 +0,0 @@
1
- # encoding: UTF-8
2
- require 'fileutils'
3
- require 'digest/sha1'
4
-
5
- module Gitenv
6
-
7
- class Copy
8
-
9
- def initialize config, file, options = {}
10
- @config, @file, @options = config, file, options
11
- end
12
-
13
- def update!
14
- if File.exists?(target) && !File.exists?(target_copy)
15
- FileUtils.mv target, target_copy
16
- end
17
- if !File.exists?(target)
18
- FileUtils.copy source, target
19
- end
20
- end
21
-
22
- def to_s
23
- color, mark, msg = status
24
- justification = @options[:justify] ? ' ' * (@options[:justify] - description.length) : ''
25
- %/ #{Paint[mark, color]} #{Paint[target, :cyan]} << #{source}#{justification}#{Paint[msg, color]}/
26
- end
27
-
28
- def description
29
- "#{target} << #{source}"
30
- end
31
-
32
- private
33
-
34
- def status
35
- if !File.exists?(target)
36
- [ :blue, "✗", "is not set up; update will create the copy" ]
37
- elsif digest(source) == digest(target)
38
- [ :green, "✓", "ok" ]
39
- elsif File.exists?(target_copy)
40
- [ :red, "✗", "already exists with backup copy" ]
41
- else
42
- [ :blue, "✗", "already exists; update will backup the file and create the copy" ]
43
- end
44
- end
45
-
46
- def target
47
- @target ||= File.join(*[ @config.to_path, target_name].compact)
48
- end
49
-
50
- def target_copy
51
- @target_copy ||= "#{target}.orig"
52
- end
53
-
54
- def target_name
55
- @options[:as] || @file
56
- end
57
-
58
- def source
59
- @source ||= File.join(*[ @config.from_path, @file ].compact)
60
- end
61
-
62
- def digest file
63
- Digest::SHA1.new.tap do |dig|
64
- File.open(file, 'rb'){ |io| dig.update io.readpartial(4096) while !io.eof }
65
- end
66
- end
67
- end
68
- end
@@ -1,3 +0,0 @@
1
- [ :enumerator, :all_files, :dot_files, :one_file ].each do |lib|
2
- require File.join(File.dirname(__FILE__), 'enumerator', lib.to_s)
3
- end
@@ -1,10 +0,0 @@
1
-
2
- module Gitenv
3
-
4
- class AllFiles < FileEnumerator
5
-
6
- def files path
7
- Dir.entries(path).select{ |f| File.file? File.join(path, f) }
8
- end
9
- end
10
- end
@@ -1,14 +0,0 @@
1
-
2
- module Gitenv
3
-
4
- class FileEnumerator
5
-
6
- def files path
7
- raise '#files not implemented'
8
- end
9
-
10
- def each path, &block
11
- files(path).each{ |f| block.call f }
12
- end
13
- end
14
- end
@@ -1,60 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- module Gitenv
4
-
5
- class Symlink
6
-
7
- def initialize config, file, options = {}
8
- @config, @file, @options = config, file, options
9
- end
10
-
11
- def update!
12
- unless File.exists? link
13
- File.symlink target, link
14
- end
15
- end
16
-
17
- def to_s
18
- color, mark, msg = status
19
- justification = @options[:justify] ? ' ' * (@options[:justify] - description.length) : ''
20
- %/ #{Paint[mark, color]} #{Paint[link, :cyan]} -> #{target}#{justification}#{Paint[msg, color]}/
21
- end
22
-
23
- def description
24
- "#{link} -> #{target}"
25
- end
26
-
27
- private
28
-
29
- def status
30
- if File.symlink? link
31
- current_target = File.expand_path File.readlink(link)
32
- if current_target == target
33
- [ :green, "✓", "ok" ]
34
- else
35
- [ :yellow, "✗", "currently points to #{current_target}; update will overwrite" ]
36
- end
37
- elsif File.file? link
38
- [ :red, "✗", "is a file; update will ignore" ]
39
- elsif File.directory? link
40
- [ :red, "✗", "is a directory; update will ignore" ]
41
- elsif File.exists? link
42
- [ :red, "✗", "exists but is not a symlink; update will ignore" ]
43
- else
44
- [ :blue, "✗", "is not set up; update will create the link" ]
45
- end
46
- end
47
-
48
- def link
49
- @link ||= File.join(*[ @config.to_path, link_name].compact)
50
- end
51
-
52
- def target
53
- @target ||= File.join(*[ @config.from_path, @file ].compact)
54
- end
55
-
56
- def link_name
57
- @options[:as] || @file
58
- end
59
- end
60
- end
@@ -1,16 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
-
4
- begin
5
- Bundler.setup(:default, :development)
6
- rescue Bundler::BundlerError => e
7
- $stderr.puts e.message
8
- $stderr.puts "Run `bundle install` to install missing gems"
9
- exit e.status_code
10
- end
11
-
12
- require 'simplecov'
13
- SimpleCov.start
14
-
15
- require 'rspec'
16
- require 'gitenv'
@@ -1,9 +0,0 @@
1
- require 'helper'
2
-
3
- describe "Version" do
4
-
5
- it "should be correct" do
6
- version_file = File.join File.dirname(__FILE__), '..', 'VERSION'
7
- Gitenv::VERSION.should == File.open(version_file, 'r').read
8
- end
9
- end