slide deck presentation tool written in pure bash

Shellchecked :sparkles:

Signed-off-by: Anirudh Oppiliappan <x@icyphox.sh>

Changed files
+25 -24
+25 -24
shlide
··· 4 4 # Each slide is a textfile under path/to/slides 5 5 6 6 # Color definitions. 7 - BLK="\e[38;5;30m" 8 - RED="\e[38;5;31m" 9 - GRN="\e[38;5;32m" 10 - YLW="\e[38;5;33m" 11 - BLU="\e[38;5;34m" 12 - PUR="\e[38;5;35m" 13 - CYN="\e[38;5;36m" 14 - RST="\e[0m" 7 + export BLK="\e[38;5;30m" 8 + export RED="\e[38;5;31m" 9 + export GRN="\e[38;5;32m" 10 + export YLW="\e[38;5;33m" 11 + export BLU="\e[38;5;34m" 12 + export PUR="\e[38;5;35m" 13 + export CYN="\e[38;5;36m" 14 + export RST="\e[0m" 15 15 16 16 # Other formatting. 17 - BLD="\e[1m" 18 - DIM="\e[2m" 19 - ITA="\e[3m" 20 - UND="\e[4m" 21 - FLS="\e[5m" 22 - REV="\e[7m" 23 - INV="\e[8m" 24 - STR="\e[9m" 17 + export BLD="\e[1m" 18 + export DIM="\e[2m" 19 + export ITA="\e[3m" 20 + export UND="\e[4m" 21 + export FLS="\e[5m" 22 + export REV="\e[7m" 23 + export INV="\e[8m" 24 + export STR="\e[9m" 25 25 26 26 lines() { 27 27 mapfile -tn 0 lines < "$1" ··· 32 32 max=0 33 33 local IFS= 34 34 while read -r line; do 35 - l=$(ansi_filter $(colorify "$line")) 35 + l=$(ansi_filter "$(colorify "$line")") 36 36 if [ "${#l}" -gt "$max" ]; then max="${#l}"; fi 37 37 done < "$1" 38 38 printf '%s\n' "$max" ··· 40 40 41 41 colorify() { 42 42 # 'eval' hack to achieve substitution for colors. 43 + # Exclude SC2154. 43 44 eval "declare dummy=\"$1\"" 44 45 printf '%b' "$dummy" 45 46 } ··· 48 49 shopt -s extglob 49 50 ansi_filter() { 50 51 local IFS= 51 - echo "${1//$'\e'[\[(]*([0-9;])[@-n]/}" 52 + printf '%s' "${1//$'\e'[\[(]*([0-9;])[@-n]/}" 52 53 #" A little fix to prevent vim syntax highlighting from breaking. 53 54 } 54 55 ··· 79 80 width=$(longest_line "$2") 80 81 81 82 # Rough estimates for the true center. 82 - ((l=$LINES/2 - $height/2)) 83 - ((c=$COLUMNS/2 - $width/2)) 83 + ((l=LINES/2 - height/2)) 84 + ((c=COLUMNS/2 - width/2)) 84 85 85 86 printf '\e[%s;%sH' "$l" "$c" 86 87 ··· 96 97 esac 97 98 # Move down and back after each print. 98 99 l=$(ansi_filter "$l") 99 - printf '\e[%sD\e[B' "$((${#l} - $reduce))" 100 + printf '\e[%sD\e[B' "$((${#l} - reduce))" 100 101 done <<< "$slide_contents" 101 102 102 103 } ··· 109 110 110 111 display_end() { 111 112 read -r LINES COLUMNS < <(stty -F /dev/tty size) 112 - ((l=$LINES/2)) 113 - ((c=$COLUMNS/2 - 8)) 113 + ((l=LINES/2)) 114 + ((c=COLUMNS/2 - 8)) 114 115 printf '\e[2J' 115 116 printf '\e[0;%sH' "$c" 116 117 printf 'END. Press q to quit.' ··· 146 147 [[ "$i" -lt 0 ]] && i=0 147 148 148 149 # Navigate on j/k/n/p and quit on q. 149 - display "$(<${slides[$i]})" "${slides[$i]}" "$i" "${#slides[@]}" 150 + display "$(<"${slides[$i]}")" "${slides[$i]}" "$i" "${#slides[@]}" 150 151 read -rsn1 input 151 152 case "$input" in 152 153 "j"|"n")