Created
March 6, 2015 19:40
-
-
Save sedrubal/e7542d4d50fdfa338bce to your computer and use it in GitHub Desktop.
bash bar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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