dit 0.3 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/dit +1 -1
- data/lib/dit.rb +51 -32
- metadata +2 -3
- data/lib/dit/cmd.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0edc19b873a4cf7c2ae46ab6e96eb0dbc8c08a24
|
4
|
+
data.tar.gz: 9520d2931559df0dc4b1455a7ea5cdedbfab2b02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c5638af480f07cf7218ae2d76f040d43eaa7e4f04dfa64e5026093987cd44421d26c440f5e6892e5a680898b6d091e5e125e374ada3af3617d42e2a33543464
|
7
|
+
data.tar.gz: b30b5f71ceaa05926160959ab829cfd1ac9086829fd7031d01e260cda6253195a82e672242bebb1c9d8e9aa4ea2194de1b668161d21f7b7ffd0e7c2cd8fc1de2
|
data/bin/dit
CHANGED
data/lib/dit.rb
CHANGED
@@ -34,7 +34,7 @@ class Dit
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def self.prompt_for_symlink_all
|
37
|
-
puts 'Dit has detected an existing git repo, and will initialize it to '
|
37
|
+
puts 'Dit has detected an existing git repo, and will initialize it to ' \
|
38
38
|
'populate your ~ directory with symlinks.'
|
39
39
|
puts 'Please confirm this by typing y, or anything else to cancel.'
|
40
40
|
response = STDIN.gets.chomp.upcase
|
@@ -60,19 +60,25 @@ class Dit
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def self.symlink_list(list)
|
63
|
+
list = get_roots list
|
64
|
+
list.each do |f|
|
65
|
+
wd_f = File.expand_path f
|
66
|
+
home_f = File.expand_path(f).gsub(Dir.getwd, Dir.home)
|
67
|
+
symlink wd_f, home_f
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.get_roots(list)
|
63
72
|
root_list = Set[]
|
64
73
|
list.each do |f|
|
65
74
|
f.strip!
|
66
75
|
root = f.split('/')[0]
|
67
76
|
root ||= f
|
68
|
-
root_list
|
77
|
+
root_list |= Set[root]
|
69
78
|
end
|
70
79
|
root_list.delete?('')
|
71
|
-
|
72
|
-
|
73
|
-
home_f = File.absolute_path(f).gsub(Dir.getwd, Dir.home)
|
74
|
-
symlink wd_f, home_f
|
75
|
-
end
|
80
|
+
%w(.gitignore README.md README).each { |i| root_list.delete(i) }
|
81
|
+
root_list
|
76
82
|
end
|
77
83
|
|
78
84
|
def self.symlink_unlinked
|
@@ -86,16 +92,34 @@ class Dit
|
|
86
92
|
|
87
93
|
def self.symlink(a, b)
|
88
94
|
if File.exist?(b)
|
89
|
-
return if
|
90
|
-
|
91
|
-
response = STDIN.gets.upcase
|
92
|
-
return unless response == 'Y'
|
95
|
+
return if File.symlink?(b) && File.readlink(b).include?(Dir.getwd)
|
96
|
+
return unless prompt_for_overwrite a, b
|
93
97
|
end
|
94
98
|
File.symlink(a, b)
|
95
99
|
rescue
|
96
100
|
puts "Failed to symlink #{a} to #{b}"
|
97
101
|
end
|
98
102
|
|
103
|
+
def self.prompt_for_overwrite(a, b)
|
104
|
+
return false if @never
|
105
|
+
(FileUtils.rm(b); return true) if @always # just this once;
|
106
|
+
puts "#{b} conflicts with #{a}. Remove #{b}? [y/n/a/s]"
|
107
|
+
puts "To always overwrite, type \"A\". To never overwrite, type \"S\""
|
108
|
+
response = STDIN.gets.upcase
|
109
|
+
case response
|
110
|
+
when 'Y'
|
111
|
+
FileUtils.rm(b)
|
112
|
+
return true
|
113
|
+
when 'A'
|
114
|
+
@always = true
|
115
|
+
FileUtils.rm(b)
|
116
|
+
return true
|
117
|
+
when 'S'
|
118
|
+
@never = true
|
119
|
+
end
|
120
|
+
false
|
121
|
+
end
|
122
|
+
|
99
123
|
def self.detect_hook(hook)
|
100
124
|
return [false, false] unless File.exist?(hook)
|
101
125
|
|
@@ -105,11 +129,11 @@ class Dit
|
|
105
129
|
puts 'Dit hook already installed.'
|
106
130
|
cannot_hook = true
|
107
131
|
elsif `cat #{hook}`.include?('#!/usr/bin/env bash')
|
108
|
-
puts "You have #{hook} hooks already that use bash, so we'll "
|
132
|
+
puts "You have #{hook} hooks already that use bash, so we'll " \
|
109
133
|
'append ourselves to the file.'
|
110
134
|
append_to_hook = true
|
111
135
|
else
|
112
|
-
puts "You have #{hook} hooks that use some foreign language, "
|
136
|
+
puts "You have #{hook} hooks that use some foreign language, " \
|
113
137
|
"so we won't interfere, but we can't hook in there."
|
114
138
|
cannot_hook = true
|
115
139
|
end
|
@@ -119,16 +143,16 @@ class Dit
|
|
119
143
|
|
120
144
|
def self.write_hook(hook_file, do_append)
|
121
145
|
File.open(hook_file, 'a') do |f|
|
122
|
-
f.
|
123
|
-
f.
|
146
|
+
f.puts '#!/usr/bin/env bash' unless do_append
|
147
|
+
f.puts '( exec ./.git/hooks/dit )'
|
124
148
|
end
|
125
149
|
end
|
126
150
|
|
127
151
|
def self.make_dit
|
128
152
|
File.open('dit', 'a') do |f|
|
129
|
-
f.
|
130
|
-
f.
|
131
|
-
f.
|
153
|
+
f.puts '#!/usr/bin/env ./.git/hooks/force-ruby'
|
154
|
+
f.puts "require 'dit'"
|
155
|
+
f.puts 'Dit.symlink_unlinked'
|
132
156
|
end
|
133
157
|
end
|
134
158
|
|
@@ -142,22 +166,15 @@ class Dit
|
|
142
166
|
if ruby_path != '/usr/bin/ruby'
|
143
167
|
ruby_folder = File.dirname(ruby_path)
|
144
168
|
File.open('force-ruby', 'a') do |f|
|
145
|
-
f.
|
146
|
-
f.
|
147
|
-
|
148
|
-
|
149
|
-
# By the way, if anyone has particular PATHs I should use for
|
150
|
-
# RVM or chruby, please let me know!
|
151
|
-
f.write "PATH=#{File.join(ENV['RBENV_ROOT'], 'shims')}:$PATH\n"
|
152
|
-
else
|
153
|
-
f.write "PATH=#{ruby_folder}:$PATH\n"
|
154
|
-
end
|
155
|
-
f.write "exec ruby \"$@\"\n"
|
169
|
+
f.puts '#!/usr/bin/env bash'
|
170
|
+
f.puts 'set -e'
|
171
|
+
f.puts 'PATH=#{ruby_folder}:$PATH'
|
172
|
+
f.puts "exec ruby \"$@\""
|
156
173
|
end
|
157
174
|
else
|
158
175
|
File.open('force-ruby', 'a') do |f|
|
159
|
-
f.
|
160
|
-
f.
|
176
|
+
f.puts '#!/usr/bin/env bash'
|
177
|
+
f.puts "exec ruby \"$@\""
|
161
178
|
end
|
162
179
|
end
|
163
180
|
end
|
@@ -176,10 +193,12 @@ class Dit
|
|
176
193
|
end
|
177
194
|
|
178
195
|
def self.version
|
179
|
-
'0.
|
196
|
+
'0.4'
|
180
197
|
end
|
181
198
|
end
|
182
199
|
|
200
|
+
# This is the thor class the CLI calls.
|
201
|
+
# It's a thin layer on top of the Dit class. See above.
|
183
202
|
class DitCMD < Thor
|
184
203
|
desc 'init', 'Initialize the current directory as a dit directory.'
|
185
204
|
def init
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.4'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kyle Fahringer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -68,7 +68,6 @@ extra_rdoc_files: []
|
|
68
68
|
files:
|
69
69
|
- bin/dit
|
70
70
|
- lib/dit.rb
|
71
|
-
- lib/dit/cmd.rb
|
72
71
|
homepage: http://github.com/vulpino/dit
|
73
72
|
licenses:
|
74
73
|
- MIT
|
data/lib/dit/cmd.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'dit'
|
2
|
-
|
3
|
-
class DitCMD < Thor
|
4
|
-
desc 'init', 'Initialize the current directory as a dit directory.'
|
5
|
-
def init
|
6
|
-
Dit.init
|
7
|
-
end
|
8
|
-
|
9
|
-
desc 'rehash', "Manually symlink everything in case a git hook didn't run."
|
10
|
-
def rehash
|
11
|
-
Dit.symlink_all
|
12
|
-
end
|
13
|
-
|
14
|
-
desc 'version', 'Print the dit version.'
|
15
|
-
def version
|
16
|
-
puts "Dit #{Dit.version} on ruby #{RUBY_VERSION}"
|
17
|
-
end
|
18
|
-
|
19
|
-
desc 'clean', 'Clean dead symlinks from your home dir.'
|
20
|
-
def clean
|
21
|
-
Dit.clean_home
|
22
|
-
end
|
23
|
-
end
|