Created
January 1, 2010 23:57
-
-
Save kch/267312 to your computer and use it in GitHub Desktop.
removes trailing spaces on every line, leading and trailing empty lines; ensures files end with a line feed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby -pi | |
# | |
# Copyright © 2010 Caio Chassot | |
# Licensed under the WTFPL <http://sam.zoy.org/wtfpl/COPYING> | |
# | |
# File Trim. (Vertical and Right trim.) | |
# Command receives file paths as arguments. Modifies them in-place. | |
# - removes trailing spaces on every line; | |
# - removes leading and trailing empty lines; | |
# - ensures files end with a line feed. | |
next !$<.eof? && $s && $s << "\n" if $_ !~ /\S/ | |
$_ = $s.to_s << $_.sub(/\s*\z/, "\n") | |
$s = ("" unless $<.eof?) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment