summaryrefslogtreecommitdiff
path: root/examples/scripts/scrollbar
blob: 388bea8e137c8429c841fa3c90307a337a739233 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/bash
#
# scrollbar - display scrolling text
#
# usage: scrollbar args
#
# A cute hack originally from Heiner Steven <hs@bintec.de>
#
# converted from ksh syntax to bash v2 syntax by Chet Ramey

WIDTH=${COLUMNS:-80}
WMINUS=$(( $WIDTH - 1 ))

[ $# -lt 1 ] && set -- TESTING

# use the bash-2.02 printf builtin
Text=$(printf "%-${WIDTH}s" "$*")
Text=${Text// /_}

while :
do
	printf "%-.${WIDTH}s\r" "$Text"
	LastC=${Text:${WMINUS}:1}
	Text="$LastC""${Text%?}"
done