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

10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
  1. #!/bin/bash
  2. # Clears the entire current line regardless of terminal size.
  3. # See the magic by running:
  4. # { sleep 1; clear_this_line ; }&
  5. function clear_this_line {
  6. printf '\r'
  7. cols="$(tput cols)"
  8. for i in $(seq "$cols"); do
  9. printf ' '
  10. done
  11. printf '\r'
  12. }
  13. # Erases the amount of lines specified.
  14. # Usage: erase_lines [AMOUNT]
  15. # See the magic by running:
  16. # { sleep 1; erase_lines 2; }&
  17. function erase_lines {
  18. # Default line count to 1.
  19. test -z "$1" && lines="1" || lines="$1"
  20. # This is what we use to move the cursor to previous lines.
  21. UP='\033[1A'
  22. # Exit if erase count is zero.
  23. [ "$lines" = 0 ] && return
  24. # Erase.
  25. if [ "$lines" = 1 ]; then
  26. clear_this_line
  27. else
  28. lines=$((lines - 1))
  29. clear_this_line
  30. for i in $(seq "$lines"); do
  31. buildtin echo "$UP"
  32. clear_this_line
  33. done
  34. fi
  35. }
  36. erase_lines "$1"