Created
March 5, 2014 18:18
-
-
Save pmuellr/9373196 to your computer and use it in GitHub Desktop.
filter for the cloud foundary `cf m` command
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 coffee | |
# filter for the cloud foundary `cf m` command; use as: | |
# cf m | cfm.coffee | |
process.stdin.setEncoding "utf8" | |
stdin = "" | |
process.stdin.on "readable", -> | |
chunk = process.stdin.read() | |
return unless chunk? | |
stdin += chunk | |
process.stdin.on "end", -> | |
lines = stdin.split "\n" | |
[crap, crap, crap, crap, lines...] = lines | |
for line in lines | |
[name, plan, desc...] = line.split /\s+/ | |
desc = desc.join " " | |
console.log "-------------------------------------------------------" | |
console.log "#{name} plan: #{plan}" | |
console.log "" | |
console.log "#{reformatted desc, 60}" | |
console.log "" | |
#------------------------------------------------------------------------------- | |
reformatted = (text, width) -> | |
words = text.split /\s+/ | |
lines = [] | |
line = "" | |
for word in words | |
if line.length + word.length < width | |
line += " " + word | |
else | |
if line is "" | |
lines.push word | |
else | |
lines.push line.trim() | |
line = word | |
lines.push line.trim() | |
lines = lines.join "\n" | |
lines = lines.trim() | |
return lines |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment