summaryrefslogtreecommitdiff
path: root/equote
diff options
context:
space:
mode:
authorNathan Lasseter <Nathan Lasseter nathan@bytemark.co.uk>2015-09-18 11:51:28 +0100
committerNathan Lasseter <Nathan Lasseter nathan@bytemark.co.uk>2015-09-18 11:51:28 +0100
commitb0a14e013b318fa87714414b8ece95780527bddf (patch)
treea9427383ab6e38a4421c9c4313043f6dfcb8e90e /equote
Initial commit
Diffstat (limited to 'equote')
-rwxr-xr-xequote31
1 files changed, 31 insertions, 0 deletions
diff --git a/equote b/equote
new file mode 100755
index 0000000..3aadaed
--- /dev/null
+++ b/equote
@@ -0,0 +1,31 @@
+#!/usr/bin/env ruby
+
+LINELENGTH = (ARGV.shift || 72).to_i
+
+lines = $stdin.readlines
+
+lines = lines.map { |line|
+ if line.length > (LINELENGTH-2) then
+ newlines = []
+ while line.length > (LINELENGTH-2) do
+ i = LINELENGTH-2
+ while line[i] != " " do
+ i -= 1
+ end
+ newlines << line[0...i]
+ line = line[i..-1]
+ end
+ newlines << line
+ newlines
+ else
+ line
+ end
+}
+
+lines = lines.flatten
+
+lines = lines.map { |line|
+ "> #{line}"
+}
+
+puts lines