Skip to content

Instantly share code, notes, and snippets.

@pmuellr
Created March 5, 2014 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmuellr/9373196 to your computer and use it in GitHub Desktop.
Save pmuellr/9373196 to your computer and use it in GitHub Desktop.
filter for the cloud foundary `cf m` command
#!/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