Sha256: ebcf91e4a60fb97340c43ab0f72bcea157c8f560e76e3d1761e685c0849d121e

Contents?: true

Size: 887 Bytes

Versions: 6

Compression:

Stored size: 887 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)
  if s.directory?
    config.strip_spaces.prune?(bn) and prune
    next
  end
  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

6 entries across 6 versions & 1 rubygems

Version Path
utils-0.0.27 bin/strip_spaces
utils-0.0.26 bin/strip_spaces
utils-0.0.25 bin/strip_spaces
utils-0.0.24 bin/strip_spaces
utils-0.0.23 bin/strip_spaces
utils-0.0.22 bin/strip_spaces