dropbox-dotfiles 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/dropbox-dotfiles +202 -0
- metadata +65 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2e1804afb6e37eb382895a92672a891efeb34349
|
4
|
+
data.tar.gz: fa58ca82d5fb50b73df68e293f1f22048af6bd86
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a6d8240e4db55f8faa655fa1f1b3643a47849b206e7a1d9c96949d3200f12613dffaac64a8c359e0e9143d5ef7cfa5b9b278e4360c63ae0796f9cef3368ca526
|
7
|
+
data.tar.gz: 133032e6514eec54f88f2fe0a58c5ad09e529cde1aec7381431ff6e6addb15340fc1f466471b257fff8dcf19bfd3e292513084914c14ea75e493931b60fd6d39
|
@@ -0,0 +1,202 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'colorize'
|
4
|
+
require 'FileUtils'
|
5
|
+
|
6
|
+
def error(message)
|
7
|
+
puts 'ERROR:'.red + ' ' + message
|
8
|
+
end
|
9
|
+
|
10
|
+
def check_if_dropbox_dir_exist
|
11
|
+
dropbox_directory = File.expand_path '~/Dropbox'
|
12
|
+
unless File.directory? dropbox_directory
|
13
|
+
error "'#{dropbox_directory}' doesn't exists or is not a directory!"
|
14
|
+
puts 'This program expect to find your Dropbox directory in your home\'s root.'
|
15
|
+
exit!
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def check_if_configuration_exist(configuration_file)
|
20
|
+
unless File.file? configuration_file
|
21
|
+
error "'#{configuration_file}' doesn't exists or is not a file!"
|
22
|
+
puts 'Is this the first time you launched Dropbox Dotfiles?'
|
23
|
+
print 'Should I create the file with an example configuration? (Y/n): '
|
24
|
+
response = gets.chomp.downcase
|
25
|
+
if response == '' or response == 'y'
|
26
|
+
create_example_configuration configuration_file
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_example_configuration(configuration_file)
|
32
|
+
File.open(configuration_file, 'w') do |f|
|
33
|
+
f.puts <<CONFIGURATION
|
34
|
+
DropboxDotfiles.configuration {
|
35
|
+
# if you want to create a link for a single file use the command file followed by its name
|
36
|
+
# file '.vimrc'
|
37
|
+
|
38
|
+
# if its a directory you want to link use the dir command followed by the name
|
39
|
+
# dir '.gem'
|
40
|
+
|
41
|
+
# when you use file and dir Dropbox Dotfiles assume that the file a directory are in your
|
42
|
+
# home. If you want to link something inside a sub directory without creating a link
|
43
|
+
# to the folder itself use the command cd to change the root then use file and dir normally.
|
44
|
+
# cd statement can be nested
|
45
|
+
# cd("Library") {
|
46
|
+
# dir 'Fonts'
|
47
|
+
# cd("Preferences") {
|
48
|
+
# file 'com.apple.Terminal.plist'
|
49
|
+
# }
|
50
|
+
# }
|
51
|
+
}
|
52
|
+
CONFIGURATION
|
53
|
+
end
|
54
|
+
rescue Exception => e
|
55
|
+
error e.message
|
56
|
+
exit!
|
57
|
+
else
|
58
|
+
puts 'Ok. File created!'
|
59
|
+
exit! 0
|
60
|
+
end
|
61
|
+
|
62
|
+
class Stats
|
63
|
+
attr_reader :links_created
|
64
|
+
attr_reader :errors
|
65
|
+
attr_reader :correct_links
|
66
|
+
|
67
|
+
def initialize
|
68
|
+
@links_created = 0
|
69
|
+
@errors = 0
|
70
|
+
@correct_links = 0
|
71
|
+
end
|
72
|
+
|
73
|
+
def correct
|
74
|
+
@correct_links += 1
|
75
|
+
end
|
76
|
+
|
77
|
+
def error
|
78
|
+
@errors += 1
|
79
|
+
end
|
80
|
+
|
81
|
+
def created
|
82
|
+
@links_created += 1
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
class DropboxDotfiles
|
87
|
+
@dropbox
|
88
|
+
@home
|
89
|
+
|
90
|
+
@stats
|
91
|
+
|
92
|
+
def initialize(dropbox, home, stats)
|
93
|
+
@stats = stats
|
94
|
+
|
95
|
+
create_dir_if_doesnt_exists dropbox
|
96
|
+
@dropbox = dropbox
|
97
|
+
|
98
|
+
create_dir_if_doesnt_exists home
|
99
|
+
@home = home
|
100
|
+
end
|
101
|
+
|
102
|
+
def DropboxDotfiles.configuration(&block)
|
103
|
+
dropbox = File.expand_path '~/Dropbox'
|
104
|
+
home = File.expand_path '~'
|
105
|
+
|
106
|
+
dp = DropboxDotfiles.new(dropbox, home, Stats.new)
|
107
|
+
dp.instance_eval &block
|
108
|
+
dp.report
|
109
|
+
end
|
110
|
+
|
111
|
+
def report
|
112
|
+
puts "#{@stats.correct_links} link were already present and correct"
|
113
|
+
puts "#{@stats.links_created} new links were created" if @stats.links_created > 0
|
114
|
+
puts "#{@stats.errors} errors" if @stats.errors > 0
|
115
|
+
end
|
116
|
+
|
117
|
+
def file(name)
|
118
|
+
create_link name, :file?
|
119
|
+
end
|
120
|
+
|
121
|
+
def cd(dir, &block)
|
122
|
+
dropbox = File.join @dropbox, dir
|
123
|
+
home = File.join @home, dir
|
124
|
+
DropboxDotfiles.new(dropbox, home, @stats).instance_eval &block
|
125
|
+
end
|
126
|
+
|
127
|
+
def dir(name)
|
128
|
+
create_link name, :directory?
|
129
|
+
end
|
130
|
+
|
131
|
+
private
|
132
|
+
def create_dir_if_doesnt_exists(dir)
|
133
|
+
unless File.directory? dir
|
134
|
+
begin
|
135
|
+
FileUtils.mkdir_p dir
|
136
|
+
rescue Exception => e
|
137
|
+
error "#{e.message}"
|
138
|
+
exit!
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def create_link(name, is)
|
144
|
+
dropbox = File.join @dropbox, name
|
145
|
+
home = File.join @home, name
|
146
|
+
type = is.to_s.delete '?'
|
147
|
+
|
148
|
+
if File.symlink? home
|
149
|
+
link = File.readlink home
|
150
|
+
if File.send is, home
|
151
|
+
if dropbox == link
|
152
|
+
@stats.correct
|
153
|
+
else
|
154
|
+
error "'#{home}' points to '#{link}' and not '#{dropbox}'"
|
155
|
+
@stats.error
|
156
|
+
end
|
157
|
+
else
|
158
|
+
error "'#{home}' points to '#{dropbox}' which is not a #{type}"
|
159
|
+
@stats.error
|
160
|
+
end
|
161
|
+
else
|
162
|
+
if File.exist? home
|
163
|
+
if File.send is, home
|
164
|
+
print "should I move '#{home}' inside Dropbox and create a link? (N/y): "
|
165
|
+
response = gets.chomp.downcase
|
166
|
+
if response == 'y'
|
167
|
+
FileUtils.move home, dropbox
|
168
|
+
puts "'#{home}' #{type} moved"
|
169
|
+
File.symlink dropbox, home
|
170
|
+
puts "link '#{home}' created"
|
171
|
+
@stats.created
|
172
|
+
else
|
173
|
+
puts "'#{home}' ignored"
|
174
|
+
end
|
175
|
+
else
|
176
|
+
error "'#{home}' is not a #{type}"
|
177
|
+
@stats.error
|
178
|
+
end
|
179
|
+
else
|
180
|
+
if File.exits? dropbox
|
181
|
+
if File.send is, dropbox
|
182
|
+
File.symlink dropbox, home
|
183
|
+
puts "link '#{home}' created"
|
184
|
+
@stats.created
|
185
|
+
else
|
186
|
+
error "'#{dropbox}' is not a #{type}"
|
187
|
+
@stats.error
|
188
|
+
end
|
189
|
+
else
|
190
|
+
error "'#{dropbox}' doesnt exists!"
|
191
|
+
@stats.error
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
configuration_file = File.expand_path '~/Dropbox/.dropbox-dotfiles.cfg'
|
199
|
+
|
200
|
+
check_if_dropbox_dir_exist
|
201
|
+
check_if_configuration_exist configuration_file
|
202
|
+
load configuration_file
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dropbox-dotfiles
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mirco Macrelli
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: colorize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.6'
|
20
|
+
- - '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.6.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.6'
|
30
|
+
- - '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.6.0
|
33
|
+
description: This gem can be used to sync a dotfiles with Dropbox
|
34
|
+
email: mmacrelli@gmail.com
|
35
|
+
executables:
|
36
|
+
- dropbox-dotfiles
|
37
|
+
extensions: []
|
38
|
+
extra_rdoc_files: []
|
39
|
+
files:
|
40
|
+
- bin/dropbox-dotfiles
|
41
|
+
homepage: https://github.com/mircomacrelli/dropbox-dotfiles
|
42
|
+
licenses:
|
43
|
+
- MIT
|
44
|
+
metadata: {}
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 2.2.0
|
62
|
+
signing_key:
|
63
|
+
specification_version: 4
|
64
|
+
summary: Dotfiles synch with Dropbox
|
65
|
+
test_files: []
|