+1
-1
Makefile
+1
-1
Makefile
+3
-3
example/1-hi.txt
+3
-3
example/1-hi.txt
+12
license
+12
license
···
1
+
2
+
3
+
The MIT License (MIT)
4
+
5
+
Copyright (c) Anirudh Oppiliappan <x@icyphox.sh>
6
+
7
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
+
9
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
+
11
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12
+
+86
-1
readme.md
+86
-1
readme.md
···
1
1
# shlide
2
2
> a slide deck presentation tool written in pure bash
3
3
4
-

4
+

5
+
6
+
## Features
7
+
8
+
- All slides are plain-text files.
9
+
- Vim like navigation.
10
+
- Text color and style formatting.
11
+
- Pure bash.
12
+
13
+
## Requirements
14
+
15
+
- `bash 4+`
16
+
17
+
## Usage
18
+
19
+
Create a directory for your slides. Name each slide starting with
20
+
a number and a hyphen, like so:
21
+
22
+
```shell
23
+
$ mkdir deck
24
+
$ touch deck/1-first-slide.txt
25
+
$ touch deck/2-another.txt
26
+
27
+
# so on
28
+
```
29
+
30
+
**Note**: Make sure to prefix the first 9 slides with a `0` (`01-foo.txt`, `02-bar.txt` ...),
31
+
if you have more than 10 slides.
32
+
33
+
Finally, run:
34
+
35
+
```shell
36
+
$ shlide deck/
37
+
```
38
+
39
+
## Controls
40
+
41
+
- Next slide: `j`, `n`, `;`, `space`, `enter`
42
+
- Previous slide: `k`, `p`, `,`, `backspace`
43
+
- Jump to first slide: `0`
44
+
- Jump to last slide: `G`
45
+
- Reload: `r`
46
+
- Quit: `q`
47
+
48
+
## Formatting
49
+
50
+
Slide content can be formatted like so:
51
+
52
+
```txt
53
+
Welcome to ${GRN}shlide${RST}. ${STR}Here${RST} are a few bullet points:
54
+
55
+
- first point
56
+
- second point
57
+
* ${ITA}sub point${RST}
58
+
* ${BLD}another${RST} sub point
59
+
```
60
+
61
+
**Note**: Make sure to `${RST}` (reset) at the end.
62
+
63
+
A full list of formatting options are below:
64
+
65
+
### Colors
66
+
67
+
|Key|Effect |
68
+
|-|-|
69
+
| `BLK` | black |
70
+
| `RED` | red |
71
+
| `GRN` | green |
72
+
| `YLW` | yellow |
73
+
| `BLU` | blue |
74
+
| `PUR` | purple |
75
+
| `CYN` | cyan |
76
+
| `RST` | reset |
77
+
78
+
### Styles
79
+
80
+
|Key|Effect |
81
+
|-|-|
82
+
| `BLD` | bold |
83
+
| `DIM` | dim |
84
+
| `ITA` | italics |
85
+
| `UND` | underline |
86
+
| `FLS` | flashing |
87
+
| `REV` | reverse |
88
+
| `INV` | invert |
89
+
| `STR` | strikethrough |
5
90
+137
-38
shlide
+137
-38
shlide
···
1
1
#!/usr/bin/env bash
2
-
#
3
-
# Usage: shlide path/to/slides/
4
-
# Each slide is a textfile under path/to/slides
2
+
# shellcheck disable=2154
3
+
#
4
+
# shlide - a slide deck presentation tool written in pure bash
5
+
# https://github.com/icyphox/shlide
6
+
#
7
+
# The MIT License (MIT)
8
+
#
9
+
# Copyright (c) 2020 Anirudh Oppiliappan <x@icyphox.sh>
5
10
6
-
# Color definitions
11
+
# Color definitions.
12
+
export BLK="\e[30m"
13
+
export RED="\e[31m"
14
+
export GRN="\e[32m"
15
+
export YLW="\e[33m"
16
+
export BLU="\e[34m"
17
+
export PUR="\e[35m"
18
+
export CYN="\e[36m"
19
+
export RST="\e[0m"
7
20
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"
21
+
# Other formatting.
22
+
export BLD="\e[1m"
23
+
export DIM="\e[2m"
24
+
export ITA="\e[3m"
25
+
export UND="\e[4m"
26
+
export FLS="\e[5m"
27
+
export REV="\e[7m"
28
+
export INV="\e[8m"
29
+
export STR="\e[9m"
15
30
16
-
lstrip() {
17
-
# See: https://github.com/dylanaraps/pure-bash-bible#strip-pattern-from-start-of-string
18
-
printf '%s\n' "${1##$2}"
31
+
lines() {
32
+
mapfile -tn 0 lines < "$1"
33
+
printf '%s\n' "${#lines[@]}"
19
34
}
20
35
21
-
get_term_size() {
36
+
longest_line() {
37
+
max=0
38
+
local IFS=
39
+
while read -r line; do
40
+
l=$(ansi_filter "$(colorify "$line")")
41
+
if [ "${#l}" -gt "$max" ]; then max="${#l}"; fi
42
+
done < "$1"
43
+
printf '%s\n' "$max"
44
+
}
22
45
23
-
# POSIX alternative to 'checkwinsize'.
24
-
read -r LINES COLUMNS < <(stty -F /dev/tty size)
46
+
colorify() {
47
+
# 'eval' hack to achieve substitution for colors.
48
+
# Exclude SC2154.
49
+
eval "declare dummy=\"$1\""
50
+
printf '%b' "$dummy"
51
+
}
25
52
53
+
# Filter out color sequences.
54
+
ansi_filter() {
55
+
shopt -s extglob
56
+
local IFS=
57
+
printf '%s' "${1//$'\e'[\[(]*([0-9;])[@-n]/}"
58
+
#" A little fix to prevent vim syntax highlighting from breaking.
59
+
shopt -u extglob
26
60
}
27
61
28
-
# navigate() {
29
-
# case "$1" in
30
-
# "j")
31
-
# }
32
62
33
63
display() {
34
64
# 1 - slide contents
35
65
# 2 - slide name
66
+
# 3 - current slide nr.
67
+
# 4 - total nr. of slides
36
68
37
69
slide_contents="$1"
38
-
# slide_name="$(lstrip $2 "[0-9]-")"
39
70
40
-
# Hides the cursor.
71
+
# Hide the cursor.
41
72
printf '\e[?25l'
42
73
43
74
# Clear the screen.
44
75
printf '\e[2J'
45
76
46
-
# Move the cursor to the center.
47
-
get_term_size
77
+
# Get screen size.
78
+
shopt -s checkwinsize; (:;:)
79
+
80
+
# Write slide number at bottom left.
81
+
printf '\e[H'
82
+
printf '\e[%sB%s/%s' "$LINES" "$(($3+1))" "$4"
83
+
84
+
# Custom calculations to center text.
85
+
height=$(lines "$2")
86
+
width=$(longest_line "$2")
48
87
49
88
# Rough estimates for the true center.
50
-
((l=0))
51
-
((c=0))
89
+
((l=LINES/2 - height/2))
90
+
((c=COLUMNS/2 - width/2))
91
+
52
92
printf '\e[%s;%sH' "$l" "$c"
53
93
54
94
while IFS= read -r line; do
95
+
reduce=0
55
96
# Print the contents of the slide file,
56
97
# line by line.
57
-
printf '%s' "$line"
98
+
l=$(colorify "$line")
99
+
printf '%s' "$l"
100
+
case $line in
101
+
"" | "\n")
102
+
((++reduce));;
103
+
esac
58
104
# Move down and back after each print.
59
-
printf '\e[%sD\e[B' "${#line}"
105
+
l=$(ansi_filter "$l")
106
+
printf '\e[%sD\e[B' "$((${#l} - reduce))"
60
107
done <<< "$slide_contents"
61
108
62
-
# Change slide on space.
63
-
read -rsn1 input
64
-
#navigate "$input"
109
+
}
110
+
111
+
die() {
112
+
printf '\e[2J'
113
+
printf '\e[?25h'
114
+
printf '\e[0H'
115
+
exit 0
116
+
}
117
+
118
+
display_end() {
119
+
((l=LINES/2))
120
+
((c=COLUMNS/2 - 8))
121
+
printf '\e[2J'
122
+
printf '\e[0;%sH' "$c"
123
+
printf 'END. Press q to quit.'
65
124
}
66
125
67
126
main() {
68
-
69
-
slides_dir="$1"
127
+
128
+
slides_dir="${1:-./}"
129
+
slides=("$slides_dir"/[0-9]*.txt)
130
+
total="${#slides[@]}"
131
+
i=0
132
+
while :; do
133
+
# Clear the screen.
134
+
printf '\e[2J'
135
+
136
+
# Capture Ctrl+C.
137
+
trap 'die' INT
138
+
139
+
# Don't go below 0.
140
+
[[ "$i" -lt 0 ]] && i=0
70
141
71
-
for f in "$slides_dir"/[0-9]*.txt; do
72
-
f_contents="$(<$f)"
73
-
display "$f_contents" "$f"
142
+
# Display END reached prompt, and then exit.
143
+
if [[ "$i" -eq "$total" ]]; then
144
+
display_end
145
+
else
146
+
display "$(<"${slides[$i]}")" "${slides[$i]}" "$i" "$total"
147
+
fi
148
+
149
+
# Navigation
150
+
read -rsn1 input
151
+
case "$input" in
152
+
"j"|"n"|""|";")
153
+
[[ "$i" -eq "$total" ]] && die
154
+
((++i))
155
+
;;
156
+
"k"|"p"|""|",")
157
+
((--i))
158
+
;;
159
+
"0")
160
+
((i=0))
161
+
;;
162
+
"G")
163
+
((i=total-1))
164
+
;;
165
+
"q")
166
+
# Return the cursor on exit.
167
+
die
168
+
;;
169
+
*)
170
+
# Reloads the slide
171
+
;;
172
+
esac
74
173
done
75
-
174
+
76
175
# Return the cursor.
77
176
printf '\e[?25h'
78
177
+105
shlide.1.scd
+105
shlide.1.scd
···
1
+
shlide(1) ["Version 1.0"]
2
+
3
+
# NAME
4
+
5
+
shlide - a slide deck presentation tool written in pure bash
6
+
7
+
# SYNOPSIS
8
+
9
+
shlide _deck-directory/_
10
+
11
+
# DESCRIPTION
12
+
13
+
Create a directory for your slides. Name each slide starting with
14
+
a number and a hyphen, like so:
15
+
16
+
$ mkdir deck++
17
+
$ touch deck/1-first-slide.txt++
18
+
$ touch deck/2-another.txt
19
+
20
+
*Note*: Make sure to prefix the first 9 slides with a *0* (e.g. 01-foo.txt, 02-bar.txt ...), if you have more than 10 slides.
21
+
22
+
Finally, run:
23
+
24
+
$ shlide deck/
25
+
26
+
# CONTROLS
27
+
28
+
Next slide:
29
+
*j*, *n*, *;*, *space*, *enter*
30
+
31
+
Previous slide:
32
+
*k*, *p*, *,*, *backspace*
33
+
34
+
Jump to first slide:
35
+
*0*
36
+
37
+
Jump to last slide:
38
+
*G*
39
+
40
+
Reload:
41
+
*r*
42
+
43
+
Quit:
44
+
*q*
45
+
46
+
# FORMATTING
47
+
48
+
Slide content can be formatted like so:
49
+
50
+
Welcome to ${GRN}shlide${RST}. ${STR}Here${RST} are a few bullet points:
51
+
52
+
\- first point++
53
+
\- second point++
54
+
\* ${ITA}sub point${RST}++
55
+
\* ${BLD}another${RST} sub point
56
+
57
+
*Note*: Make sure to add ${RST} (reset) at the end.
58
+
59
+
A full list of formatting options are below:
60
+
61
+
## Colors
62
+
63
+
[[ *Key*
64
+
:- *Effect*
65
+
|- BLK
66
+
:- black
67
+
|- RED
68
+
:- red
69
+
|- GRN
70
+
:- green
71
+
|- YLW
72
+
:- yellow
73
+
|- BLU
74
+
:- blue
75
+
|- PUR
76
+
:- purple
77
+
|- CYN
78
+
:- cyan
79
+
|- RST
80
+
:- reset
81
+
82
+
## Styles
83
+
84
+
[[ *Key*
85
+
:- *Effect*
86
+
|- BLD
87
+
:- bold
88
+
|- DIM
89
+
:- dim
90
+
|- ITA
91
+
:- italics
92
+
|- UND
93
+
:- underline
94
+
|- FLS
95
+
:- flashing
96
+
|- REV
97
+
:- reverse
98
+
|- INV
99
+
:- invert
100
+
|- STR
101
+
:- strikethrough
102
+
103
+
# LICENSES
104
+
105
+
shlide is licensed under the MIT license.