dotfiles 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/dot_files.rb +1 -0
- data/lib/dot_files/command.rb +8 -0
- data/lib/dot_files/commands/files.rb +4 -9
- metadata +2 -2
data/lib/dot_files.rb
CHANGED
data/lib/dot_files/command.rb
CHANGED
@@ -113,6 +113,14 @@ module DotFiles
|
|
113
113
|
req = request("save", :data => {:dot_file => {:path => path, :file => contents}})
|
114
114
|
req ? true : false
|
115
115
|
end
|
116
|
+
|
117
|
+
def save_local_file(filename, contents)
|
118
|
+
local_path = File.join(ENV['HOME'], filename)
|
119
|
+
FileUtils.mkdir_p(File.dirname(local_path))
|
120
|
+
File.open(local_path, 'w') { |f| f.write(contents) }
|
121
|
+
DotFiles.config.shas[filename] = Digest::SHA1.hexdigest(contents)
|
122
|
+
DotFiles.config.save
|
123
|
+
end
|
116
124
|
|
117
125
|
private
|
118
126
|
|
@@ -41,10 +41,8 @@ command :sync do
|
|
41
41
|
puts "{{downloading}} #{file[:filename]}"
|
42
42
|
contents = remote_file_contents(file[:filename])
|
43
43
|
puts "{{saving}} #{file[:filename]}"
|
44
|
-
|
45
|
-
|
46
|
-
puts "{{saved}} #{contents.size.to_s} bytes to #{local_path}"
|
47
|
-
DotFiles.config.shas[file[:filename]] = Digest::SHA1.hexdigest(contents)
|
44
|
+
save_local_file(file[:filename], contents)
|
45
|
+
puts "{{saved}} #{contents.size.to_s} bytes to #{file[:filename]}"
|
48
46
|
when :update_remote
|
49
47
|
puts "{{uploading}} #{file[:filename]}"
|
50
48
|
local_path = File.join(ENV['HOME'], file[:filename])
|
@@ -79,12 +77,9 @@ desc 'Pull a remote file to your local file system'
|
|
79
77
|
usage 'pull path/to/dotfile'
|
80
78
|
command :pull do |path|
|
81
79
|
filename = path.gsub(/\A#{ENV['HOME']}\//, '')
|
82
|
-
local_path = File.join(ENV['HOME'], filename)
|
83
80
|
if contents = remote_file_contents(filename)
|
84
|
-
|
85
|
-
|
86
|
-
DotFiles.config.save
|
87
|
-
puts "Downloaded #{contents.size} bytes to #{local_path}."
|
81
|
+
save_local_file(filename, contents)
|
82
|
+
puts "Downloaded #{contents.size} bytes to #{filename}."
|
88
83
|
else
|
89
84
|
error "Couldn't download remote file from '#{filename}'. Does it exist?"
|
90
85
|
end
|