25 lines
963 B
Ruby
25 lines
963 B
Ruby
module Dunlop::FileSed
|
|
|
|
def self.in_place(filename, sed_expressions)
|
|
expression_list = Array.wrap(sed_expressions).map { |exp| "-e '#{exp}'" }.join(' ')
|
|
if /Darwin/i =~ %x[uname]
|
|
#BSD
|
|
%x[ LC_CTYPE=C LANG=C gsed -i'' -r #{expression_list} #{Shellwords.escape(filename)} ]
|
|
raise 'error in sed command line' unless $?.exitstatus == 0
|
|
else
|
|
#GNU
|
|
%x[ LC_CTYPE=C LANG=C sed -i'' -r #{expression_list} #{Shellwords.escape(filename)} ]
|
|
raise 'error in sed command line' unless $?.exitstatus == 0
|
|
end
|
|
end
|
|
|
|
def self.fix_line_endings(filename)
|
|
return if filename.to_s.end_with?('.xlsx')
|
|
res = %x[dos2unix -f #{Shellwords.escape(filename)} > /dev/null 2>&1]
|
|
raise "error in dos2unix command line (#{res})" unless $?.exitstatus == 0
|
|
res = %x[dos2unix -f -c mac #{Shellwords.escape(filename)} > /dev/null 2>&1]
|
|
raise "error in dos2unix command line mac (#{res})" unless $?.exitstatus == 0
|
|
end
|
|
|
|
end
|