-
Notifications
You must be signed in to change notification settings - Fork 0
/
rsvp
49 lines (35 loc) · 964 Bytes
/
rsvp
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
# Connect the cleanup function to the usual signals
trap "cleanup; exit" SIGHUP SIGINT SIGTERM
# Check if the file exists
[ -f "$1" ] || echo "File not found!" || exit
function cleanup() {
# Restore the screen content
tput rmcup
# Make the cursor visible again
tput cvvis
}
# Save the screen contents
tput smcup
# Loop over all words
while read line
do
## Get viewport width and height
height=$(tput lines)
width=$(tput cols)
# Get the length of the current word
line_length=${#line}
# Clear the screen
clear
# Put the cursor on the middle of the terminal (a bit more to the left, to center the word)
tput cup "$((height/2))" "$((($width-$line_length)/2))"
# Hide the cursor
tput civis
# Print the word
printf "$line"
# Sleep one second
sleep 1
# Pass the words separated by a newline to the loop
done < <(tr ' ' '\n' < "$1")
# Call the cleanup function
cleanup