summaryrefslogtreecommitdiff
path: root/equote
blob: 3aadaedc008b5b0c90e66a44e1f9e4b1e2fbc2b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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