Sha256: c154be2b1311ea0ec1ba6c6780ee03279ead25bc8f6eefc7cb8f9fb8863d3867

Contents?: true

Size: 1.34 KB

Versions: 8

Compression:

Stored size: 1.34 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

  -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

pathes = ARGV.empty? ?  %w[.] : ARGV
pathes = pathes.map { |p| File.expand_path(p) }

suffix = args['I'].ask_and_send(:split, /[\s,]+/).to_a

config = Utils::Config::ConfigFile.new
config.parse_config_file File.expand_path('~/.utilsrc')

find(*pathes, :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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
utils-0.0.48 bin/strip_spaces
utils-0.0.47 bin/strip_spaces
utils-0.0.46 bin/strip_spaces
utils-0.0.45 bin/strip_spaces
utils-0.0.44 bin/strip_spaces
utils-0.0.43 bin/strip_spaces
utils-0.0.42 bin/strip_spaces
utils-0.0.41 bin/strip_spaces