lib/sym/app/commands/bash_completion.rb in sym-2.8.0 vs lib/sym/app/commands/bash_completion.rb in sym-2.8.1
- old
+ new
@@ -6,25 +6,28 @@
required_options [:bash_support]
try_after :generate_key, :open_editor, :encrypt, :decrypt
def ok
- '[OK]'.bold.green
+ ' '.bold.green
end
def execute
file = opts[:bash_support]
out = ''
Sym::Constants::Bash::Config.each_pair do |key, config|
script_name = key.to_s
- if (!File.exist?(config[:dest])) ||
- (File.exist?(config[:dest]) && !FileUtils.identical?(config[:source], config[:dest]))
- FileUtils.cp(config[:source], config[:dest])
- out << "#{} installing #{config[:dest].bold.blue }...\n"
- else
+
+ # This removes the old version of this file.
+ remove_old_version(out, config[:dest])
+
+ if File.exist?(config[:dest]) && File.read(config[:source]) == File.read(config[:dest])
out << "#{ok} file #{config[:dest].bold.blue } exists, and is up to date.\n"
+ else
+ FileUtils.cp(config[:source], config[:dest])
+ out << "#{ok} installing #{config[:dest].bold.blue }...\n"
end
out << if File.exist?(file)
if File.read(file).include?(config[:script])
"#{ok} BASH script #{file.bold.yellow} already sources #{script_name.bold.blue}.\n"
@@ -49,9 +52,18 @@
File.open(file, 'a') do |fd|
fd.write(script + "\n")
end
end
+ def remove_old_version(out, file)
+ if file =~ /\.bash$/
+ old_file = file.gsub(/\.bash$/, '')
+ if File.exist?(old_file)
+ out << "Removing old version — #{old_file.bold.magenta}..."
+ FileUtils.rm_f old_file
+ end
+ end
+ end
end
end
end
end