Skip to content

Instantly share code, notes, and snippets.

@alifeee
Created March 26, 2024 20:03
Show Gist options
  • Save alifeee/a6f14aad9caed6b8a861df0e2850aa10 to your computer and use it in GitHub Desktop.
Save alifeee/a6f14aad9caed6b8a861df0e2850aa10 to your computer and use it in GitHub Desktop.
Simple bar chart generation with bash
#!/bin/bash
# make bar chart from $prog, $total, $n_seg as $1 $2 $3
# example:
# > ./bar.sh 25 100 12
# ███░░░░░░░░░
awk -v prog=$1 -v TOTAL=$2 -v TOTSEG=$3 'BEGIN {
frac = prog / TOTAL;
segs = frac * TOTSEG;
segs_int = int(sprintf("%.0f", segs));
for (s=0; s<segs_int; s++) {
printf "%s", "█";
}
for (s=0; s<(TOTSEG - segs_int); s++) {
printf "%s", "░";
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment