summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrian m. carlson <sandals@crustytoothpaste.net>2020-02-16 04:47:43 +0000
committerbrian m. carlson <sandals@crustytoothpaste.net>2020-02-16 04:47:43 +0000
commitf1c8ec1fb79c3e4fdb86ba9c0e6c42e1a88ac135 (patch)
treea1edbc27443b537231500ae8035992522d5e5af0
parentd2b78e1e821428b62bbd510637bb8a825dbf19eb (diff)
bin: add a script to unwrap text
Oftentimes, one wants to write text in a wrapped format (such as in a commit message) but enter it into a system which normally does wrapping on its own (such as the GitHub web interface). Add a script, format-text, which preserves double newlines as paragraph markers but unwraps paragraphs into single lines. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
-rwxr-xr-xbin/format-text14
1 files changed, 14 insertions, 0 deletions
diff --git a/bin/format-text b/bin/format-text
new file mode 100755
index 0000000..3ff6251
--- /dev/null
+++ b/bin/format-text
@@ -0,0 +1,14 @@
+#!/usr/bin/env ruby
+#
+#/ format-text [FILE...]
+#/
+#/ Formats text in the specified files or from stding, removing newlines within
+#/ a paragraph.
+
+if ARGV[0] == "--help"
+ puts File.read($0).each_line.select { |l| l.start_with?("#/") }.
+ map { |l| l.gsub(/^#\/ ?/, '') }
+ exit 0
+end
+
+puts ARGF.read.split("\n\n").map { |c| c.gsub("\n", ' ') }.join("\n\n")