Sha256: 62f2bf0bd44577024eb057156ab2781f176a66d5873372313f3fa522dac7e963
Contents?: true
Size: 1.24 KB
Versions: 7
Compression:
Stored size: 1.24 KB
Contents
#!/usr/bin/env ruby require 'tins/go' include Tins::GO require 'tins/secure_write' include Tins::SecureWrite require 'utils' include Utils::Find class ::File include Utils::FileXt end def usage puts <<-EOT Usage: #{File.basename($0)} [OPTS] [PATHES] PATHES are the directory and file pathes that are search for files to be stripped. Options are -h display this help Version is #{File.basename($0)} #{Utils::VERSION}. EOT exit 1 end args = go 'h' args['h'] and usage pathes = ARGV.empty? ? %w[.] : ARGV pathes = pathes.map { |p| File.expand_path(p) } config = Utils::Config::ConfigFile.new config.parse_config_file File.expand_path('~/.utilsrc') find(*pathes) 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
Version data entries
7 entries across 7 versions & 1 rubygems