diff options
author | davidpkj <davidpenkow1@gmail.com> | 2024-06-03 11:57:18 +0200 |
---|---|---|
committer | davidpkj <davidpenkow1@gmail.com> | 2024-06-03 11:57:18 +0200 |
commit | cbfd64346441200e3df8df6ad54fc76c99d25f1c (patch) | |
tree | 075030b8cc3676f9834e08916685a0967655a44e /scripts/.local/bin | |
parent | f8f7a0bcde016dffb61772a97fe2fdb7a06fe082 (diff) |
Add marquee.sh script
Diffstat (limited to 'scripts/.local/bin')
-rwxr-xr-x | scripts/.local/bin/personal/external/marquee.sh | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/scripts/.local/bin/personal/external/marquee.sh b/scripts/.local/bin/personal/external/marquee.sh new file mode 100755 index 0000000..e2157c9 --- /dev/null +++ b/scripts/.local/bin/personal/external/marquee.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash +delay=0.2 +fixed=0 +l=0 l2=0 w2=0 +while getopts 'fw:d:h' o; do + + case $o in + d) delay="$OPTARG" ;; + f) fixed=1 ;; + w) w="$((OPTARG))" ;; + h) nr=1 ;& + *) + cat >&2 <<EOF +Usage: $0 [ -h | [ [opts] [text ...] ] + +Prints [text ...] as a scrolling marquee + +Options: + -f fix width: do not change on SIGWINCH + -w n set width: do not detect (implies -f) + -d n set delay: see documentation on Bash's \`sleep\` + -h see this help +EOF + exit $((1 - nr)) + ;; + esac + +done +shift "$((OPTIND - 1))" +pre="$*" + +if ((w == 0)); then + winch_handler() { + w="$(tput cols)" + s="$(printf "%${w}s" "$pre")" + } + winch_handler + ((fixed != 1)) && trap "winch_handler" SIGWINCH +else + s="$(printf "%${w}s" "$pre")" +fi + +while sleep "$delay"; do + printf '%s\r' "${s:$l:$w}${s:$l2:$w2}" + ((l = (l + 1) % ${#s})) + ((l2 = (l - ${#s}) > 0 ? (l - ${#s}) : 0)) + ((w2 = (l + w - ${#s}) > 0 ? (l + w - ${#s}) : 0)) +done |