+7
Makefile
+7
Makefile
+8
example/1-hi.txt
+8
example/1-hi.txt
+7
example/2-another.txt
+7
example/2-another.txt
+5
readme.md
+5
readme.md
+81
shlide
+81
shlide
···
1
+
#!/usr/bin/env bash
2
+
#
3
+
# Usage: shlide path/to/slides/
4
+
# Each slide is a textfile under path/to/slides
5
+
6
+
# Color definitions
7
+
8
+
#BLK="\e[30m"
9
+
#RED="\e[31m"
10
+
#GRN="\e[32m"
11
+
#YLW="\e[33m"
12
+
#BLU="\e[34m"
13
+
#PUR="\e[35m"
14
+
#CYN="\e[36m"
15
+
16
+
lstrip() {
17
+
# See: https://github.com/dylanaraps/pure-bash-bible#strip-pattern-from-start-of-string
18
+
printf '%s\n' "${1##$2}"
19
+
}
20
+
21
+
get_term_size() {
22
+
23
+
# POSIX alternative to 'checkwinsize'.
24
+
read -r LINES COLUMNS < <(stty -F /dev/tty size)
25
+
26
+
}
27
+
28
+
# navigate() {
29
+
# case "$1" in
30
+
# "j")
31
+
# }
32
+
33
+
display() {
34
+
# 1 - slide contents
35
+
# 2 - slide name
36
+
37
+
slide_contents="$1"
38
+
# slide_name="$(lstrip $2 "[0-9]-")"
39
+
40
+
# Hides the cursor.
41
+
printf '\e[?25l'
42
+
43
+
# Clear the screen.
44
+
printf '\e[2J'
45
+
46
+
# Move the cursor to the center.
47
+
get_term_size
48
+
49
+
# Rough estimates for the true center.
50
+
((l=0))
51
+
((c=0))
52
+
printf '\e[%s;%sH' "$l" "$c"
53
+
54
+
while IFS= read -r line; do
55
+
# Print the contents of the slide file,
56
+
# line by line.
57
+
printf '%s' "$line"
58
+
# Move down and back after each print.
59
+
printf '\e[%sD\e[B' "${#line}"
60
+
done <<< "$slide_contents"
61
+
62
+
# Change slide on space.
63
+
read -rsn1 input
64
+
#navigate "$input"
65
+
}
66
+
67
+
main() {
68
+
69
+
slides_dir="$1"
70
+
71
+
for f in "$slides_dir"/[0-9]*.txt; do
72
+
f_contents="$(<$f)"
73
+
display "$f_contents" "$f"
74
+
done
75
+
76
+
# Return the cursor.
77
+
printf '\e[?25h'
78
+
79
+
}
80
+
81
+
main "$@"