Skip to content

Instantly share code, notes, and snippets.

@henryefranks
Created September 9, 2018 10:06
Show Gist options
  • Save henryefranks/5ff9c575581b4863a6b87e5fefe8eec0 to your computer and use it in GitHub Desktop.
Save henryefranks/5ff9c575581b4863a6b87e5fefe8eec0 to your computer and use it in GitHub Desktop.
A Bash script for drawing CLI boxes
box_width=$(tput cols)
function create_line() {
input_width=$(($(echo "$*" | wc -c) - 1))
if [ $# -lt 1 ]; then
input_width=0
fi
half_width=$(($(($box_width - $input_width)) / 2))
for i in `seq 1 $half_width`; do
echo -n '-'
done
echo -n $*
half_width=$(($box_width - $half_width - $input_width))
for i in `seq 1 $half_width`; do
echo -n '-'
done
echo
}
function box_output() {
echo -n '| ' "$*"
input_length=$(echo $* | wc -c)
for i in `seq 1 $(($box_width - $input_length - 4))`; do
echo -n ' '
done
echo ' |'
}
function create_divider() {
echo -n '|'
for i in `seq 1 $(($box_width - 2))`; do
echo -n '-'
done
echo -n '|'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment