slide deck presentation tool written in pure bash

Compare changes

Choose any two refs to compare.

Changed files
+267 -52
example
+1 -1
Makefile
··· 1 1 PREFIX ?= /usr 2 2 3 3 install: 4 - install -Dm755 pw $(DESTDIR)$(PREFIX)/bin/shlide 4 + install -Dm755 shlide $(DESTDIR)$(PREFIX)/bin/shlide 5 5 6 6 uninstall: 7 7 rm -f $(DESTDIR)$(PREFIX)/bin/shlide
+3 -3
example/1-hi.txt
··· 1 1 HI THERE 2 2 3 - Welcome to ${GRN}shlide${RST}. ${YLW}Here${RST} are a few bullet points: 3 + Welcome to ${GRN}shlide${RST}. ${STR}Here${RST} are a few bullet points: 4 4 5 5 - first point 6 6 - second point 7 - * sub point 8 - * ${RED}another${RST} sub point 7 + * ${ITA}sub point${RST} 8 + * ${BLD}another${RST} sub point
+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 +
+82 -3
readme.md
··· 1 1 # shlide 2 2 > a slide deck presentation tool written in pure bash 3 3 4 - ![scrot](https://x.icyphox.sh/NBq.png) 4 + ![scrot](https://u.peppe.rs/k7.png) 5 5 6 6 ## Features 7 7 8 8 - All slides are plain-text files. 9 - - Navigation using `j` / `k` or `n` / `p` 10 - - [WIP] Colors and bold/italic formatting using terminal escape sequences. 9 + - Vim like navigation. 10 + - Text color and style formatting. 11 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 | 90 +
+64 -45
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[38;5;30m" 9 - RED="\e[38;5;31m" 10 - GRN="\e[38;5;32m" 11 - YLW="\e[38;5;33m" 12 - BLU="\e[38;5;34m" 13 - PUR="\e[38;5;35m" 14 - CYN="\e[38;5;36m" 15 - RST="\e[0m" 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" 16 30 17 31 lines() { 18 32 mapfile -tn 0 lines < "$1" ··· 23 37 max=0 24 38 local IFS= 25 39 while read -r line; do 26 - l=$(ansi_filter $(colorify "$line")) 40 + l=$(ansi_filter "$(colorify "$line")") 27 41 if [ "${#l}" -gt "$max" ]; then max="${#l}"; fi 28 42 done < "$1" 29 43 printf '%s\n' "$max" ··· 31 45 32 46 colorify() { 33 47 # 'eval' hack to achieve substitution for colors. 48 + # Exclude SC2154. 34 49 eval "declare dummy=\"$1\"" 35 50 printf '%b' "$dummy" 36 51 } 37 52 38 53 # Filter out color sequences. 39 - shopt -s extglob 40 54 ansi_filter() { 55 + shopt -s extglob 41 56 local IFS= 42 - echo "${1//$'\e'[\[(]*([0-9;])[@-n]/}" 57 + printf '%s' "${1//$'\e'[\[(]*([0-9;])[@-n]/}" 43 58 #" A little fix to prevent vim syntax highlighting from breaking. 59 + shopt -u extglob 44 60 } 45 61 46 62 ··· 52 68 53 69 slide_contents="$1" 54 70 55 - # Hides the cursor. 71 + # Hide the cursor. 56 72 printf '\e[?25l' 57 73 58 74 # Clear the screen. 59 75 printf '\e[2J' 60 76 61 - # Get screen size 77 + # Get screen size. 62 78 shopt -s checkwinsize; (:;:) 63 79 64 - # Write slide number at bottom left 80 + # Write slide number at bottom left. 65 81 printf '\e[H' 66 82 printf '\e[%sB%s/%s' "$LINES" "$(($3+1))" "$4" 67 83 68 - # Custom calculations to center text 84 + # Custom calculations to center text. 69 85 height=$(lines "$2") 70 86 width=$(longest_line "$2") 71 87 72 88 # Rough estimates for the true center. 73 - ((l=$LINES/2 - $height/2)) 74 - ((c=$COLUMNS/2 - $width/2)) 89 + ((l=LINES/2 - height/2)) 90 + ((c=COLUMNS/2 - width/2)) 75 91 76 92 printf '\e[%s;%sH' "$l" "$c" 77 93 ··· 87 103 esac 88 104 # Move down and back after each print. 89 105 l=$(ansi_filter "$l") 90 - printf '\e[%sD\e[B' "$((${#l} - $reduce))" 106 + printf '\e[%sD\e[B' "$((${#l} - reduce))" 91 107 done <<< "$slide_contents" 92 108 93 109 } ··· 95 111 die() { 96 112 printf '\e[2J' 97 113 printf '\e[?25h' 114 + printf '\e[0H' 98 115 exit 0 99 116 } 100 117 101 118 display_end() { 102 - read -r LINES COLUMNS < <(stty -F /dev/tty size) 103 - ((l=$LINES/2)) 104 - ((c=$COLUMNS/2 - 8)) 119 + ((l=LINES/2)) 120 + ((c=COLUMNS/2 - 8)) 105 121 printf '\e[2J' 106 122 printf '\e[0;%sH' "$c" 107 123 printf 'END. Press q to quit.' ··· 111 127 112 128 slides_dir="${1:-./}" 113 129 slides=("$slides_dir"/[0-9]*.txt) 130 + total="${#slides[@]}" 114 131 i=0 115 - while true; do 132 + while :; do 116 133 # Clear the screen. 117 134 printf '\e[2J' 118 135 119 136 # Capture Ctrl+C. 120 137 trap 'die' INT 121 138 122 - # Display END reached prompt, and then exit 123 - [[ "$i" -eq "${#slides[@]}" ]] && { 124 - display_end 125 - read -rsn1 input 126 - case "$input" in 127 - "j"|"n"|"q") 128 - die 129 - ;; 130 - *) 131 - ((--i)) 132 - ;; 133 - esac 134 - } 135 - 136 139 # Don't go below 0. 137 140 [[ "$i" -lt 0 ]] && i=0 138 141 139 - # Navigate on j/k/n/p and quit on q. 140 - display "$(<${slides[$i]})" "${slides[$i]}" "$i" "${#slides[@]}" 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 141 150 read -rsn1 input 142 - case "$input" in 143 - "j"|"n") 151 + case "$input" in 152 + "j"|"n"|""|";") 153 + [[ "$i" -eq "$total" ]] && die 144 154 ((++i)) 145 155 ;; 146 - "k"|"p") 156 + "k"|"p"|""|",") 147 157 ((--i)) 148 158 ;; 159 + "0") 160 + ((i=0)) 161 + ;; 162 + "G") 163 + ((i=total-1)) 164 + ;; 149 165 "q") 150 166 # Return the cursor on exit. 151 167 die 168 + ;; 169 + *) 170 + # Reloads the slide 152 171 ;; 153 172 esac 154 173 done
+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.