113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/bashman.rb', line 113
def save(dir = '~/.bashman/profiles', profile_name = 'default', overwrite = false, verbose = false)
dir = File.expand_path(dir)
FileUtils.mkdir_p(dir) if not Dir.exists?(dir)
@timestamp = Time.now.to_i
manifest = "#{dir}/#{profile_name}.json"
puts "Saving manifest file #{manifest}" if verbose
timestamp = nil
if not overwrite
if File.exists?(manifest)
begin
timestamp = JSON.parse(File.read(manifest))['@timestamp']
rescue
timestamp = File.mtime(manifest).to_i if timestamp.nil?
end
FileUtils.mv(manifest, "#{manifest}.#{timestamp}")
end
end
if instance_variable_defined?("@shell")
shell = @shell.to_hash
@shell.save_dotfiles("#{dir}/#{profile_name}.tar.gz", timestamp, overwrite)
@shell = shell
end
if instance_variable_defined?("@homebrew")
homebrew = @homebrew.to_hash
@homebrew = homebrew
end
manifest_content = self.to_json
File.open(manifest, 'w') do |file|
file.write(manifest_content)
end
end
|