Sha256: 216cf28abf4a5d5ae7132651122838674c00e1bc9fe482c688718498df736270

Contents?: true

Size: 937 Bytes

Versions: 1

Compression:

Stored size: 937 Bytes

Contents

#!/usr/bin/env ruby

require 'tins/secure_write'
include Tins::SecureWrite
require 'utils'
include Utils::Find

class ::File
  include Utils::FileXt
end

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?(filename) 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

1 entries across 1 versions & 1 rubygems

Version Path
utils-0.0.29 bin/strip_spaces