lib/git/gsub.rb in git-gsub-0.0.1 vs lib/git/gsub.rb in git-gsub-0.0.2

- old
+ new

@@ -15,13 +15,30 @@ def self.version puts Git::Gsub::VERSION end def self.gsub *args - from, to, path, = args + from, to, path, = args.map do |arg| + Shellwords.escape arg if arg + end + if to.nil? + abort "No argument to gsub was given" + end + target_files = (`git grep -l #{from} #{path}`).each_line.map(&:chomp).join ' ' - system %|gsed -i s/#{Shellwords.escape from}/#{Shellwords.escape to}/g #{target_files}| + if system_support_gsed? + system %|gsed -i "" s/#{from}/#{to}/g #{target_files}| + else + system %|sed -i "" -e s/#{from}/#{to}/g #{target_files}| + end + end + + private + + def self.system_support_gsed? + `which gsed` + $?.success? end end end