dropbox-dotfiles 1.1.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/dropbox-dotfiles +55 -20
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d6165496469dee4cea42d571896e056ab06ecbf8
4
- data.tar.gz: dc4987a1e8389bf926e2783bbb9289f1056d8b53
3
+ metadata.gz: 28bb1f871fa6772cf29c21ee1983e380c0aac32e
4
+ data.tar.gz: 6e63284bb0ebf3b823952c4313d12bf0454d0933
5
5
  SHA512:
6
- metadata.gz: bd8e286bf612d02019995ba5a8662e66fd5452166b2226c77e513124f6b3314f18825ab566b6e709c78653f062d31160a1a9b2fda0e6d4d9fd2d029fa332f901
7
- data.tar.gz: 0bb930fdda7ad057021ad12b7b48e9e5ab7e19f34c1a3dffd97b08df8ef2a20345286ca7af677c93a9c97dec743f4c50e1ba08bbff139ec08b6c5e24d9d1a670
6
+ metadata.gz: af6be4bea823e34ad23b9c3f3ae5ecb4bc0de74e2e5e7666f04a8997253946f5463845682e3090735f75d17e593b7075c8c911cbc840003794f99a3e172a3de2
7
+ data.tar.gz: 11a605bcadbe0a3d493a6740eea4f5f8796420f25a3d8f54da905c6d5728be77734981c63aadfa20262b4e3d24108de54a86f7418d3e3c0aaeeef983a1c97585
data/bin/dropbox-dotfiles CHANGED
@@ -7,24 +7,57 @@ def error(message)
7
7
  puts "#{message}".red
8
8
  end
9
9
 
10
+ def get_dropbox_dir_from_dotfile
11
+ dotfile = File.expand_path '~/.dropbox-dotfiles'
12
+
13
+ if File.exists? dotfile
14
+ File.read dotfile
15
+ end
16
+ end
17
+
18
+ def get_dropbox_dir_from_args
19
+ if ARGV.size == 1
20
+ ARGV[0]
21
+ end
22
+ end
23
+
24
+ def get_dropbox_directory
25
+ directory = '~/Dropbox'
26
+
27
+ from_dotfile = get_dropbox_dir_from_dotfile
28
+ if from_dotfile.to_s != ''
29
+ directory = from_dotfile
30
+ end
31
+
32
+ from_args = get_dropbox_dir_from_args
33
+ if from_args.to_s != ''
34
+ directory = from_args
35
+
36
+ File.open(File.expand_path('~/.dropbox-dotfiles'), 'w+') do |f|
37
+ f.write(from_args)
38
+ end
39
+ end
40
+
41
+ File.expand_path directory
42
+ end
43
+
10
44
  def check_if_dropbox_dir_exist
11
- dropbox_directory = File.expand_path '~/Dropbox'
45
+ dropbox_directory = File.expand_path $my_dropbox_directory
12
46
  unless File.directory? dropbox_directory
13
47
  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
48
  exit!
16
49
  end
17
50
  end
18
51
 
19
52
  def check_if_dotfiles_dir_exist
20
- dotfiles_directory = File.expand_path '~/Dropbox/Dotfiles'
53
+ dotfiles_directory = File.expand_path File.join $my_dropbox_directory, 'Dotfiles'
21
54
  unless File.directory? dotfiles_directory
22
55
  error "'#{dotfiles_directory}' doesn't exists or is not a directory!"
23
- puts 'Should I create the directory for you? (y/N): '
24
- response = gets.chomp.downcase
56
+ print 'Should I create the directory for you? (y/N): '
57
+ response = STDIN.gets.chomp.downcase
25
58
  if response == 'y'
26
59
  begin
27
- FileUtils.mkdir_p dotfiles_directory
60
+ Dir.mkdir dotfiles_directory
28
61
  rescue Exception => e
29
62
  error e.message
30
63
  exit!
@@ -34,14 +67,14 @@ def check_if_dotfiles_dir_exist
34
67
  end
35
68
 
36
69
  def check_if_configuration_exist(configuration_file)
37
- if File.exist? configuration_file
70
+ if File.exists? configuration_file
38
71
  unless File.file? configuration_file
39
72
  error "'#{configuration_file}' is not a file!"
40
73
  end
41
74
  else
42
75
  error "'#{configuration_file}' doesn't exists!"
43
76
  print 'Should I create a new the file with an example configuration? (y/N): '
44
- response = gets.chomp.downcase
77
+ response = STDIN.gets.chomp.downcase
45
78
  if response == 'y'
46
79
  create_example_configuration configuration_file
47
80
  else
@@ -80,7 +113,7 @@ rescue Exception => e
80
113
  else
81
114
  puts 'File created!'.green
82
115
  puts "Now open '#{configuration_file}' in your favourite text editor and edit the configuration."
83
- puts "When you're done launch dropbox-dotfiles again."
116
+ puts 'When you\'re done launch dropbox-dotfiles again.'
84
117
  exit! 0
85
118
  end
86
119
 
@@ -125,7 +158,7 @@ class DropboxDotfiles
125
158
  end
126
159
 
127
160
  def DropboxDotfiles.configuration(&block)
128
- dropbox = File.expand_path '~/Dropbox/Dotfiles'
161
+ dropbox = File.expand_path File.join $my_dropbox_directory, 'Dotfiles'
129
162
  home = File.expand_path '~'
130
163
 
131
164
  dp = DropboxDotfiles.new(dropbox, home, Stats.new)
@@ -135,7 +168,7 @@ class DropboxDotfiles
135
168
 
136
169
  def report
137
170
  if @stats.correct_links == 0 and @stats.links_created == 0 and @stats.errors == 0
138
- puts "Your configuration file is empty!"
171
+ puts 'Your configuration file is empty!'
139
172
  else
140
173
  puts "#{@stats.correct_links} link were already present and correct"
141
174
  puts "#{@stats.links_created} new links were created" if @stats.links_created > 0
@@ -160,12 +193,12 @@ class DropboxDotfiles
160
193
  private
161
194
  def create_dir_if_doesnt_exists(dir)
162
195
  unless File.directory? dir
163
- if File.exist? dir
196
+ if File.exists? dir
164
197
  error "'#{dir}' is not a directory!"
165
198
  exit!
166
199
  else
167
200
  begin
168
- FileUtils.mkdir_p dir
201
+ Dir.mkdir dir
169
202
  rescue Exception => e
170
203
  error "#{e.message}"
171
204
  exit!
@@ -193,12 +226,12 @@ private
193
226
  correct_link dropbox, home, is
194
227
  end
195
228
  else
196
- if File.exist? home
229
+ if File.exists? home
197
230
  if File.send is, home
198
- if File.exist? dropbox
231
+ if File.exists? dropbox
199
232
  print "Dropbox already contains '#{home}'"
200
233
  print "Do you want to create a backup of '#{home}' and then create the link? (y/N): "
201
- response = gets.chomp.downcase
234
+ response = STDIN.gets.chomp.downcase
202
235
  if response == 'y'
203
236
  backup = home + '.old'
204
237
  FileUtils.move home, backup
@@ -209,7 +242,7 @@ private
209
242
  end
210
243
  else
211
244
  print "Should I move '#{home}' inside Dropbox and create a link? (y/N): "
212
- response = gets.chomp.downcase
245
+ response = STDIN.gets.chomp.downcase
213
246
  if response == 'y'
214
247
  FileUtils.move home, dropbox
215
248
  File.symlink dropbox, home
@@ -242,9 +275,9 @@ private
242
275
  end
243
276
 
244
277
  def correct_link(dropbox, home, is)
245
- if File.exist? dropbox and File.send is, dropbox
278
+ if File.exists? dropbox and File.send is, dropbox
246
279
  puts 'Do you want to create a backup of the link and then correct it? (y/N): '
247
- response = gets.chomp.downcase
280
+ response = STDIN.gets.chomp.downcase
248
281
  if response == 'y'
249
282
  backup = File.join home, '.old'
250
283
  File.move home, backup
@@ -259,7 +292,9 @@ private
259
292
  end
260
293
  end
261
294
 
262
- configuration_file = File.expand_path '~/Dropbox/Dotfiles/.configuration'
295
+ $my_dropbox_directory = get_dropbox_directory
296
+ puts "using '#{$my_dropbox_directory}' as the Dropbox directory"
297
+ configuration_file = File.join $my_dropbox_directory, 'Dotfiles/.configuration'
263
298
 
264
299
  check_if_dropbox_dir_exist
265
300
  check_if_dotfiles_dir_exist
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dropbox-dotfiles
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mirco Macrelli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-04 00:00:00.000000000 Z
11
+ date: 2014-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -60,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
60
  version: '0'
61
61
  requirements: []
62
62
  rubyforge_project:
63
- rubygems_version: 2.2.2
63
+ rubygems_version: 2.4.1
64
64
  signing_key:
65
65
  specification_version: 4
66
66
  summary: Easy dotfiles's synchronization via Dropbox