Created
December 18, 2015 18:04
-
-
Save jfredett/5ee504e77884a9beeb79 to your computer and use it in GitHub Desktop.
box.rb
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 | |
lines = ARGF.each_line.to_a.map(&:chomp) | |
line_max = lines.map(&:length).max | |
lines = lines.map do |line| | |
offset = (line_max + line.length) / 2 | |
line = line.rjust(offset).ljust(line_max) | |
'* ' + line + ' *' | |
end | |
line_max = lines.map(&:length).max | |
puts '*' * line_max | |
puts lines | |
puts '*' * line_max |
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
(1:01) (/Users/fredettej) (ruby-2.1.6) | |
≈≈≈ ruby box.rb <<HERE | |
> I met a traveller from an antique land | |
> Who said: "Two vast and trunkless legs of stone | |
> Stand in the desert. Near them, on the sand, | |
> Half sunk, a shattered visage lies, whose frown, | |
> And wrinkled lip, and sneer of cold command, | |
> Tell that its sculptor well those passions read | |
> Which yet survive, stamped on these lifeless things, | |
> The hand that mocked them and the heart that fed: | |
> And on the pedestal these words appear: | |
> 'My name is Ozymandias, king of kings: | |
> Look on my works, ye Mighty, and despair!' | |
> Nothing beside remains. Round the decay | |
> Of that colossal wreck, boundless and bare | |
> The lone and level sands stretch far away." | |
> HERE | |
******************************************************** | |
* I met a traveller from an antique land * | |
* Who said: "Two vast and trunkless legs of stone * | |
* Stand in the desert. Near them, on the sand, * | |
* Half sunk, a shattered visage lies, whose frown, * | |
* And wrinkled lip, and sneer of cold command, * | |
* Tell that its sculptor well those passions read * | |
* Which yet survive, stamped on these lifeless things, * | |
* The hand that mocked them and the heart that fed: * | |
* And on the pedestal these words appear: * | |
* 'My name is Ozymandias, king of kings: * | |
* Look on my works, ye Mighty, and despair!' * | |
* Nothing beside remains. Round the decay * | |
* Of that colossal wreck, boundless and bare * | |
* The lone and level sands stretch far away." * | |
******************************************************** |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I actually tossed this in my ~/bin as
box
. I made this based on someones question in #neovim, they wanted something in vim to do this on-the-fly. I suggested just writing the external script then wiring it in. I think they found a plugin that does similar (EasyAlign), but I was already half done with the script.I make no claims as to bug-free-ness.