Skip to content

Instantly share code, notes, and snippets.

@sedrubal
Created March 6, 2015 19:40
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 sedrubal/e7542d4d50fdfa338bce to your computer and use it in GitHub Desktop.
Save sedrubal/e7542d4d50fdfa338bce to your computer and use it in GitHub Desktop.
bash bar
#!/bin/bash
#########################
# example #
#########################
# $ ./bash_bar.sh 60 100
#[||||||||||||||||||||||||||||||||||||||||||||||||||||||| 60%]
#
value=$1
width=$2
if (( $width < 7 )); then
width="7"
fi
width=$(($width - 7))
mappedval=$(($value * $width / 100))
red='\033[0;31m'
green='\033[0;32m'
NC='\033[0m' # No Color
color="${green}"
if (( $value <= 40 )); then
color="${red}"
fi
str="[${color}"
for (( i=0; i<$mappedval; i++ ))
do
str="$str|"
done
for (( i=$mappedval; i<=width; i++ ))
do
str="$str "
done
echo -e "$str$value%${NC}]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment