dit 0.2.3 → 0.3
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/cmd.rb +23 -0
- data/lib/dit.rb +33 -6
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 842ec58e97f7f0b07c8d2d246fccf573f4414675
|
4
|
+
data.tar.gz: 9d8810fca2dee2624ba6f0c30c245cb199a7a32b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5aba260ee163c1120040d36fe400994645eaa2decca5e399f4b9d6f085175257bb99a0203314ff2ed2897dd8aa9b76550b097de438e7098ee9462e752ce1700d
|
7
|
+
data.tar.gz: 939a7a10e38c2fae3e510be92ab8c9ee07862fd000a926c760368c67f45f55d8b3792f543dc396534a9b0968d4cf30776269e0087f2964271802c08214317c32
|
data/bin/dit
CHANGED
data/lib/dit/cmd.rb
ADDED
@@ -0,0 +1,23 @@
|
|
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
|
data/lib/dit.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'thor'
|
2
2
|
require 'git'
|
3
3
|
require 'os'
|
4
|
-
require 'json'
|
5
4
|
require 'fileutils'
|
5
|
+
require 'set'
|
6
6
|
|
7
7
|
# This is the class where all the dit work is done.
|
8
8
|
# The thor class is basically a very thin layer on top of this that just
|
@@ -60,8 +60,15 @@ class Dit
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def self.symlink_list(list)
|
63
|
+
root_list = Set[]
|
63
64
|
list.each do |f|
|
64
65
|
f.strip!
|
66
|
+
root = f.split('/')[0]
|
67
|
+
root ||= f
|
68
|
+
root_list = root_list | Set[root]
|
69
|
+
end
|
70
|
+
root_list.delete?('')
|
71
|
+
root_list.each do |f|
|
65
72
|
wd_f = File.absolute_path f
|
66
73
|
home_f = File.absolute_path(f).gsub(Dir.getwd, Dir.home)
|
67
74
|
symlink wd_f, home_f
|
@@ -77,11 +84,13 @@ class Dit
|
|
77
84
|
symlink_list `git ls-tree -r #{current_branch} --name-only`.split("\n")
|
78
85
|
end
|
79
86
|
|
80
|
-
def self.repo
|
81
|
-
Git.open(Dir.getwd)
|
82
|
-
end
|
83
|
-
|
84
87
|
def self.symlink(a, b)
|
88
|
+
if File.exist?(b)
|
89
|
+
return if (File.symlink?(b) && File.readlink(b).include(Dir.getwd))
|
90
|
+
puts "#{b} conflicts with #{a}. Remove #{b}? [yN]"
|
91
|
+
response = STDIN.gets.upcase
|
92
|
+
return unless response == 'Y'
|
93
|
+
end
|
85
94
|
File.symlink(a, b)
|
86
95
|
rescue
|
87
96
|
puts "Failed to symlink #{a} to #{b}"
|
@@ -153,8 +162,21 @@ class Dit
|
|
153
162
|
end
|
154
163
|
end
|
155
164
|
|
165
|
+
def self.clean_home
|
166
|
+
Dir.chdir(Dir.home) do
|
167
|
+
existing_dotfiles = Dir.glob('.*')
|
168
|
+
existing_dotfiles.each do |f|
|
169
|
+
next if f == '.' || f == '..'
|
170
|
+
if File.symlink?(f)
|
171
|
+
f_abs = File.readlink(f)
|
172
|
+
File.delete(f) unless File.exist?(f_abs)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
156
178
|
def self.version
|
157
|
-
'0.
|
179
|
+
'0.3'
|
158
180
|
end
|
159
181
|
end
|
160
182
|
|
@@ -173,4 +195,9 @@ class DitCMD < Thor
|
|
173
195
|
def version
|
174
196
|
puts "Dit #{Dit.version} on ruby #{RUBY_VERSION}"
|
175
197
|
end
|
198
|
+
|
199
|
+
desc 'clean', 'Clean dead symlinks from your home dir.'
|
200
|
+
def clean
|
201
|
+
Dit.clean_home
|
202
|
+
end
|
176
203
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.3'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kyle Fahringer
|
@@ -68,6 +68,7 @@ extra_rdoc_files: []
|
|
68
68
|
files:
|
69
69
|
- bin/dit
|
70
70
|
- lib/dit.rb
|
71
|
+
- lib/dit/cmd.rb
|
71
72
|
homepage: http://github.com/vulpino/dit
|
72
73
|
licenses:
|
73
74
|
- MIT
|
@@ -93,3 +94,4 @@ signing_key:
|
|
93
94
|
specification_version: 4
|
94
95
|
summary: Dit is a dotfiles manager that thinks it's git.
|
95
96
|
test_files: []
|
97
|
+
has_rdoc:
|