Giter Club home page Giter Club logo

shell-progressbar's Introduction

shell-progressbar

A progressbar for shell scripts inspired by APT

Table of contents

bar

For a POSIX compliant version see instructions in branch POSIX

Installation:

Put this anywhere in your script by using cURL

. <(curl -sLo- "https://git.io/progressbar")

or by using wget

. <(wget -qO- "https://git.io/progressbar")

Usage:

Make a call to

bar::start

before any progress should be reported. This will setup the status line by shrinking the terminal scroll area by one row. Then determine the total steps to be reported - either you're using this in a loop or do manual reporting in your script. What ever way suits your needs, make a call to

bar::status_changed <steps done> <total steps>

whenever progress is made. This function will then determine if the status line should be updated.

Finally make a call to

bar::stop

when you're done and this function will restore the terminal size.

Example

#!/usr/bin/env bash

. <(curl -sLo- "https://git.io/progressbar")

bar::start

StuffToDo=("Stuff1" "Stuff2" "Stuff3")

TotalSteps=${#StuffToDo[@]}

for Stuff in ${StuffToDo[@]}; do
  # Do stuff
  echo "Invoking ${Stuff} to do some stuffs..."
  StepsDone=$((${StepsDone:-0}+1))
  bar::status_changed $StepsDone $TotalSteps
  sleep 1
done

bar::stop

Customization

If you want to customize your progress string then change the following variables, shown below with defaults

LEFT_BRACKET=${LEFT_BRACKET:-"["}
RIGHT_BRACKET=${RIGHT_BRACKET:-"]"}
FILL=${FILL:-"#"}
REMAIN=${REMAIN:-"."}

You can change foreground and background color by setting these variables

foreground="$(tput setaf 0)" # black
background="$(tput setab 2)" # green

you can also tweak how often reporting should be done (in case of great number of steps and quick progressing) by setting reporting_steps to a value bigger than 1

shell-progressbar's People

Contributors

phenonymous avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.