Skip to content

Instantly share code, notes, and snippets.

@JohannesBuchner
Last active August 29, 2015 14:23
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 JohannesBuchner/11e6d213eb879124087a to your computer and use it in GitHub Desktop.
Save JohannesBuchner/11e6d213eb879124087a to your computer and use it in GitHub Desktop.
Console progress bar -- takes stdin from arbitrary commands and plots a progress bar
"""
SYNOPSIS: ./myprog | python console-progress.py
example for myprog:
#!/bin/bash
echo 100
for i in $(seq 1 100)
do
sleep 1
echo $i
done
"""
import progressbar
import sys
end = sys.stdin.readline()
pbar = progressbar.ProgressBar(
widgets=[progressbar.Percentage(), progressbar.Counter('%5d'), progressbar.Bar(), progressbar.ETA()],
maxval=float(end)).start()
while True:
current = sys.stdin.readline()
if current is None:
break
pbar.update(float(current))
pbar.finish()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment