2 ms·
I'm old-school: progressline() { local s=`ttysize w` local n=0 while read x; do for i in `seq $n`; do echo -ne "\e[2K\e[A" do
by teo_zero 2y ago
I'm old-school:
progressline() {
local s=`ttysize w`
local n=0
while read x; do
for i in `seq $n`; do
echo -ne "\e[2K\e[A"
done
echo -ne "\e[2K\r$x"
n=$((${#x}/$s))
done
echo
}
- kattouf 2y agoNice! I would replace `ttysize w` with `tput cols` for use on macOS, and it works. However, for some reason, it erases too many lines when I tested it. Maybe something is going wrong with the "n" calculation. For test I used `ping google.com | progressline`
- teo_zero 2y agoYes, "n" calculation is approximate: it's just the number of chars divided by the terminal's width. No guarantees it works with UTF-8, escape sequences, or if the terminal get resized while it's running... Sorry, this is just a quick hack!
- kattouf 2y agoGot it, no need to sorry, this is a still cool example :thumbs-up: