Sha256: 7cf0863222304b9ae51d0e6277fa5f5749010354f91ee7d3965e383d70646f2d
Contents?: true
Size: 1.57 KB
Versions: 77
Compression:
Stored size: 1.57 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 -t COLUMNS turn tabs into COLUMNS spaces -I SUFFIXES list of suffixes -h display this help Version is #{File.basename($0)} #{Utils::VERSION}. EOT exit 1 end args = go 'I:t:h' args[?h] and usage unless ARGV.empty? paths = ARGV.map { |p| File.expand_path(p) } end suffix = Array(args[?I]) config = Utils::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/tabs 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]+$/, '') if tabs = args[?t] line.gsub!(/\t/, ' ' * Integer(tabs)) end 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
77 entries across 77 versions & 1 rubygems