mirror of
https://github.com/elenapan/dotfiles.git
synced 2025-12-27 07:44:56 +08:00
Former-commit-id: 46c2bf7d26
Former-commit-id: ec0b4e689f3f8e97d837848929a1a6a9e45f779b
Former-commit-id: 19f055447f5fd666a270a51cf98b05d70716e826
46 lines
No EOL
1.3 KiB
Bash
Executable file
46 lines
No EOL
1.3 KiB
Bash
Executable file
# Scrolling text
|
|
LIMIT=12
|
|
SEPERATOR=" ~~~ "
|
|
SEPERATOR_LENGTH="$(echo ${#SEPERATOR})"
|
|
|
|
i=1
|
|
while :
|
|
do
|
|
# Get input and create the full string that will be used
|
|
INPUT="$@"
|
|
INPUT_LENGTH="$(echo ${#INPUT})"
|
|
LOOPTAIL="$(echo $INPUT | cut -c -$LIMIT)"
|
|
FULLSTRING="$(echo "$INPUT$SEPERATOR$LOOPTAIL")"
|
|
|
|
if [ $INPUT_LENGTH -le $LIMIT ]; then
|
|
# Song has a smaller title than the limit, so no need to scroll.
|
|
echo -n " "
|
|
#echo -e -n "$INPUT"
|
|
|
|
#Justify - left
|
|
#SPACES=$(($LIMIT-$INPUT_LENGTH+1))
|
|
#echo -n "$INPUT" | awk -v spaces=$SPACES '{printf "%s%*.s\n", $0, spaces, " "}'
|
|
|
|
#Justify - center
|
|
SPACES_AFTER=$(($LIMIT-$(((${#INPUT}+$LIMIT)/2))))
|
|
printf "%*s\n" $(((${#INPUT}+$LIMIT)/2 + 1)) "$INPUT" | awk -v spaces=$SPACES_AFTER '{printf "%s%*.s\n", $0, spaces, " "}'
|
|
|
|
else
|
|
LOOPTAIL="$(echo $INPUT | cut -c -$LIMIT)"
|
|
FULLSTRING="$(echo "$INPUT$SEPERATOR$LOOPTAIL")"
|
|
|
|
echo -n " "
|
|
# Show only LIMIT characters, from i to i+LIMIT. Output scrolls due to incrementing i
|
|
echo -n $FULLSTRING | cut -c $i-$(($LIMIT+$i))
|
|
#echo -n $FULLSTRING | awk -v charlimit="$LIMIT" -v start="$i" '{print substr($0,start,charlimit)}'
|
|
|
|
# If we have shown the full string, start over
|
|
if [ $i -eq $(($INPUT_LENGTH+$SEPERATOR_LENGTH)) ]; then
|
|
i=0
|
|
fi
|
|
|
|
i=$(($i+1))
|
|
fi
|
|
|
|
sleep 1
|
|
done |