ruby 'mind.rand' | awk '{ print $1 }'

ruby: print in the same line

I’ve always tried to make my scripts’ responses prettier and less crowded, and I came across something like the following piece of code, that helped me a lot lately

#!/usr/bin/env ruby
STDOUT.sync = true
bars = ['/','-','\\','|']
i=1
while i do
  print "\rrunning #{bars[i%4]}"
  i += 1
  sleep 1
end
trap("INT") {
  print "\n\n"
  exit
}


If you like to see updates without flooding your terminal screen, this is one of the best ways to do it.

Leave a Reply

Powered by Wordpress | Designed by Elegant Themes