MIAOU-BASH is a collection of settings and helpers for leveraging BASH. Developer-friendly, it may be used as solo package with or without the miaou project.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

42 lines
1.0 KiB

#!/bin/bash
# Clears the entire current line regardless of terminal size.
# See the magic by running:
# { sleep 1; clear_this_line ; }&
clear_this_line() {
printf '\r'
cols="$(tput cols)"
for i in $(seq "$cols"); do
printf ' '
done
printf '\r'
}
# Erases the amount of lines specified.
# Usage: erase_lines [AMOUNT]
# See the magic by running:
# { sleep 1; erase_lines 2; }&
erase_lines() {
# Default line count to 1.
test -z "$1" && lines="1" || lines="$1"
# This is what we use to move the cursor to previous lines.
UP='\033[1A'
# Exit if erase count is zero.
[ "$lines" = 0 ] && return
# Erase.
if [ "$lines" = 1 ]; then
clear_this_line
else
lines=$((lines - 1))
clear_this_line
for i in $(seq "$lines"); do
buildtin echo "$UP"
clear_this_line
done
fi
}
erase_lines "$1"