Sha256: eb2fc791c931b25124dfeecc65eef0ab0ebf0cc352c63441602f37c4fd8b7e11
Contents?: true
Size: 1.46 KB
Versions: 9
Compression:
Stored size: 1.46 KB
Contents
#!/usr/bin/env ruby require 'tins/go' include Tins::GO require 'tins/secure_write' include Tins::SecureWrite require 'tins/find' include Tins::Find require 'utils' class ::File include Utils::FileXt end def usage puts <<-EOT Usage: #{File.basename($0)} [OPTS] [PATHS] PATHS are the directory and file paths that are search for files to be stripped. Options are -I SUFFIXES list of suffixes -h display this help Version is #{File.basename($0)} #{Utils::VERSION}. EOT exit 1 end args = go 'I:h' args['h'] and usage unless ARGV.empty? paths = ARGV.map { |p| File.expand_path(p) } end suffix = args['I'].ask_and_send(:split, /[\s,]+/).to_a config = Utils::Config::ConfigFile.new config.configure_from_paths if paths find(*(paths + [ { :suffix => suffix} ])) do |filename| bn, s = File.basename(filename), File.stat(filename) s.symlink? and next if s.directory? config.strip_spaces.prune?(bn) and prune next end s.file? or next config.strip_spaces.skip?(bn) and next File.ascii?(filename) or next STDOUT.puts "Stripping spaces from #{filename.inspect}." secure_write(filename) do |output| File.open(filename) do |file| old_mode = file.stat.mode file.each do |line| line.gsub!(/[ \t\v]+$/, '') output.write line end File.chmod old_mode, output.path end end end else for line in STDIN line.gsub!(/[ \t\v]+$/, '') STDOUT.write line end end
Version data entries
9 entries across 9 versions & 1 rubygems