summaryrefslogtreecommitdiff
path: root/box
diff options
context:
space:
mode:
authorNæþ'n Lasseter <Næþ'n Lasseter nathan@bytemark.co.uk>2016-09-29 14:20:52 +0100
committerNæþ'n Lasseter <Næþ'n Lasseter nathan@bytemark.co.uk>2016-09-29 14:20:52 +0100
commit0c8741059abcaaed99e627e42b99c50a17abbf08 (patch)
treeaa3e5df103066eb68d39fea0b88db68ceb5570d5 /box
parente6e6fe3cd13aaecf83cf3105c3fcd81db97481b5 (diff)
New scripts
Diffstat (limited to 'box')
-rwxr-xr-xbox46
1 files changed, 46 insertions, 0 deletions
diff --git a/box b/box
new file mode 100755
index 0000000..a4eb7b0
--- /dev/null
+++ b/box
@@ -0,0 +1,46 @@
+#!/usr/bin/env ruby
+
+require 'optparse'
+
+options = {
+ :border => 3,
+ :margin => 1,
+ :character => '='
+}
+
+parser = OptionParser.new do |opt|
+ opt.banner = "Usage: box [OPTIONS] WORDS"
+
+ opt.on("-c", "--border-character", :REQUIRED, "Border character (default: =)") do |c|
+ options[:character] = c
+ end
+ opt.on("-b", "--border-width", :REQUIRED, "Left and right border width (default: 3)") do |b|
+ options[:border] = b.to_i
+ end
+ opt.on("-m", "--margin-width", :REQUIRED, "Left and right margin width (default: 1)") do |m|
+ options[:margin] = m.to_i
+ end
+ opt.on("-h", "--help", "Print usage") do
+ puts opt.banner
+ puts opt.summarize
+ exit 0
+ end
+end
+
+parser.parse!
+
+if ARGV.length <= 0 then
+ exit
+end
+
+input = ARGV.join(' ').chomp
+
+len = input.length + 2 * options[:border] + 2 * options[:margin]
+
+puts options[:character] * len
+puts options[:character] * options[:border] +
+ " " * options[:margin] +
+ input +
+ " " * options[:margin] +
+ options[:character] * options[:border]
+puts options[:character] * len