280 lines
7.5 KiB
Bash
Executable File
280 lines
7.5 KiB
Bash
Executable File
#!/bin/bash
|
||
|
||
VERSION=20140417
|
||
|
||
function display_self {
|
||
$0 $0
|
||
exit 0
|
||
}
|
||
[ -z "$1" ] && display_self
|
||
[ "$1" = "-h" ] && display_self
|
||
|
||
[ -f "$1" ] || {
|
||
echo Cannot find file: $1
|
||
exit 1
|
||
}
|
||
|
||
function display_slide {
|
||
j=$(( $2 + 1 ))
|
||
echo -en "$CLS"
|
||
awk 'match($0,/^# /){
|
||
c++;
|
||
print c $0;
|
||
}
|
||
!/^# /{
|
||
print $0;
|
||
}
|
||
' "$1" | sed -n '/^'$2'# /,/^'$j'# /p' | grep -v "^$j# " | sed -e 's,^'$i'\(# .*\),'$H'\1'$Z',' -e ${HROW}'s/^\(.*\)/'$H$Y'\1'$Z'/' | eval sed $REGEX
|
||
}
|
||
function slide_exec {
|
||
# find executables in the slide
|
||
j=$(( $2 + 1 ))
|
||
#echo -en "$CLS"
|
||
while read line
|
||
do eval $line > /dev/null 2>&1 &
|
||
done < <(
|
||
awk 'match($0,/^# /){
|
||
c++;
|
||
print c $0;
|
||
}
|
||
!/^# /{
|
||
print $0;
|
||
}
|
||
' "$1" | sed -n '/^'$2'# /,/^'$j'# /p' | grep "\&(.*)" | sed -e 's,[^\&]*\&( ,,' -e 's,)[^)]*,,' )
|
||
# restore cursor position to bottom of slide
|
||
echo -ne "${E}u"
|
||
while read line
|
||
do eval $line
|
||
done < <(
|
||
awk 'match($0,/^# /){
|
||
c++;
|
||
print c $0;
|
||
}
|
||
!/^# /{
|
||
print $0;
|
||
}
|
||
' "$1" | sed -n '/^'$2'# /,/^'$j'# /p' | grep "\$(.*)" | sed -e 's,[^\$]*\$( ,,' -e 's, )[^)]*,,' )
|
||
|
||
}
|
||
|
||
|
||
E='\x1b['
|
||
H="${E}1m"
|
||
Z="${E}0m"
|
||
CLS="${E}2J${E}H"
|
||
#list of text colors:
|
||
BLACK="${E}30m"
|
||
R="${E}31m"
|
||
G="${E}32m"
|
||
B="${E}34m"
|
||
Y="${E}33m"
|
||
M="${E}35m"
|
||
C="${E}36m"
|
||
W="${E}37m"
|
||
#list of BG colors:
|
||
BGR="${E}41m"
|
||
BGG="${E}42m"
|
||
BGB="${E}44m"
|
||
BGY="${E}43m"
|
||
BGM="${E}45m"
|
||
BGC="${E}46m"
|
||
BGW="${E}47m"
|
||
|
||
CONF_LINE=( \${H} \${Z} \${R} \${G} \${B} \${Y} \${M} \${C} \${W}
|
||
\${BLACK} \${BGR} \${BGG} \${BGB} \${BGY} \${BGM} \${BGC} \${BGW} )
|
||
|
||
for (( r=0; r<${#CONF_LINE[@]}; r++ ));
|
||
do value=CONF_LINE[$r]
|
||
replace=$( eval echo ${!value} )
|
||
REGEX="$REGEX -e 's/\(${CONF_LINE[$r]}\)/"${replace}"/g'"
|
||
done
|
||
REGEX="$REGEX -e 's/^\$(\([^)]\{20\}\).*)/\$(\1...)/g'"
|
||
#echo $REGEX
|
||
#exit
|
||
|
||
i=1
|
||
MENU=1
|
||
HROW=1
|
||
while true
|
||
do
|
||
# print slide $i
|
||
NO_SLIDES=$( grep -ce "^# " "$1" )
|
||
SLIDE_CHARS=$(( ${#i} + ${#NO_SLIDES} +1 ))
|
||
COLS=$(( $( tput cols ) - $SLIDE_CHARS ))
|
||
LINES=$( tput lines )
|
||
[ "$cmd" = "e" ] && read -N 1 foo
|
||
display_slide "$1" $i
|
||
# save cursor location
|
||
echo -ne "${E}s"
|
||
# ask for user input
|
||
# 1 back, 2 forward, q exit, m menu
|
||
echo -ne "${Z}${E}1;${COLS}H"
|
||
[ -z "$MENU" ] || {
|
||
echo -ne "${i}/${NO_SLIDES}"
|
||
echo -ne "${E}1B${E}3D1:▶"
|
||
echo -ne "${E}1B${E}3D2:◀"
|
||
echo -ne "${E}1B${E}3Dq:x"
|
||
echo -ne "${E}1B${E}3Dm:▲${E}4A"
|
||
}
|
||
read -s -N 1 cmd
|
||
# Escape inputed if arrow keys used
|
||
[ "$cmd" = "" ] && read -s -N 2 cmd
|
||
|
||
case "$cmd" in
|
||
2|"[D"|"[5")
|
||
i=$(( $i - 1 ))
|
||
[ $i -lt 1 ] && i=1
|
||
HROW=1
|
||
;;
|
||
1|"[C"|"[6"|"")
|
||
i=$(( $i + 1 ))
|
||
[ $i -gt $NO_SLIDES ] && i=$NO_SLIDES
|
||
HROW=1
|
||
;;
|
||
4|"[A")
|
||
HROW=$(( $HROW - 1 ))
|
||
[ $HROW -lt 1 ] && HROW=1
|
||
;;
|
||
3|"[B")
|
||
HROW=$(( $HROW + 1 ))
|
||
[ $HROW -gt $LINES ] && HROW=$LINES
|
||
;;
|
||
m)
|
||
[ -z "$MENU" ] && {
|
||
MENU=1
|
||
} || {
|
||
unset MENU
|
||
}
|
||
;;
|
||
x|q)
|
||
echo -ne "${E}1E"
|
||
exit
|
||
;;
|
||
e)
|
||
slide_exec "$1" $i
|
||
;;
|
||
esac
|
||
done
|
||
|
||
done
|
||
exit
|
||
"
|
||
# Markdown Slide Presenter: MarkSlider
|
||
|
||
* This tool prints a text file as slides,
|
||
retaining the formatting. Consider
|
||
using markdown syntax.
|
||
* Syntax ref: http://daringfireball.net/projects/markdown/syntax
|
||
* The only parsed syntax is the new slide syntax:
|
||
A row starting with '# '
|
||
|
||
## How to use ##
|
||
* Give the markdown file as argument
|
||
* Move to the next slide with key 1, arrow right, space..
|
||
* Move to the previous slide with key 2, arrow left
|
||
* Exit with q or x
|
||
* Hide menu with m
|
||
* The numbers on the right show the current
|
||
and number of slides in this presentation
|
||
|
||
# Hints: Tables
|
||
|
||
* Create tables with "ncsv -m"
|
||
|
||
Object Area Perimeter
|
||
------- ----- ----------
|
||
1 358 68.28
|
||
2 444 77.36
|
||
3 507 92.18
|
||
4 1026 118.6
|
||
5 539 84.18
|
||
|
||
# Hints: Plots
|
||
* Create plots with gnuplot:
|
||
set term dumb 60 15 enhanced
|
||
set parametric; set trange [0:10*pi]; set yrange[-5*pi:5*pi]
|
||
set xrange[-10*pi:10*pi]; plot t*cos(t), t*sin(t)
|
||
15 ++-----*-+---**--+--------+-------+**-----*-------++
|
||
|+ ** + ** + *****t*cos(t), t*sin(t)*******+|
|
||
| * ** *** *** ** * |
|
||
10 ++ * ** *** ** ** * ++
|
||
| ** * ** ******** ** * * |
|
||
5 ++ * ** * *** ** * ** ** ++
|
||
| * * * ** ** ** * * |
|
||
0 ++ * * * * **** * * * * ++
|
||
| * * * * * ** ** * * *
|
||
| * * * * ** *** * ** ** *
|
||
-5 ++ * * * ** ***** ** * * **
|
||
| * ** * ** *** ** * *|
|
||
-10 ++ ** * ** *** **** ** * *+
|
||
| * ** ** ****** ** ** * |
|
||
|+ * + * *** + *** ** * +|
|
||
-15 ++----*--+--*----+-**-----+-----**+------*+----*--++
|
||
-30 -20 -10 0 10 20 30
|
||
|
||
# Hints: ${R}Co${Y}lo${G}rs
|
||
|
||
* Use ANSI codes directly for colors, or shortcuts:
|
||
${R}red: ${ [1DR}, ${G}green: ${ [1DG}, ${B}blue: ${ [1DB}${Z}
|
||
Colors: R G B C M Y W BLACK
|
||
${H}Bright modifier: ${ [1DH}, ex: ${H}${Y}yellow ${ [1DH}${ [1DY}${Z}
|
||
Background colors:${H}${C}${BGM} bright cyan on magenta ${ [1DH}${ [1DC}${ [1DBGM} ${Z}
|
||
Background colors: BGR BGG BGB BGC BGM BGY BGW
|
||
Reset colors with ${ [1DZ}
|
||
|
||
# Hints: Presenting
|
||
|
||
* Use a terminal with large font, perhaps 80 columns on screen
|
||
* Fullscreen often with F11
|
||
┌──────┐
|
||
* Get creative with │Ascii!│
|
||
└┬────┬┘
|
||
* Run any command with pressing "e" on a slide with
|
||
syntax beginning a row:
|
||
* "$ [1D( command )" to print the output
|
||
* "& [1D( command )" run process in background
|
||
|
||
&( xeyes )
|
||
$( ls )
|
||
[s$( echo You can hide commands too... )[1K[uHidden command
|
||
|
||
# Hints: Other tools
|
||
|
||
* Check out tools like:
|
||
* toilet
|
||
m " ""# m
|
||
mm#mm mmm mmm # mmm mm#mm
|
||
# #" "# # # #" # #
|
||
# # # # # #"""" #
|
||
"mm "#m#" mm#mm "mm "#mm" "mm
|
||
* boxes
|
||
_ ._ _ , _ ._
|
||
(_ ' ( ` )_ .__)
|
||
( ( ( ) `) ) _)
|
||
(__ (_ (_ . _) _) ,__)
|
||
`~~`\ ' . /`~~`
|
||
,::: ; ; :::,
|
||
':::::::::::::::'
|
||
_jgs______/_ __ \__________
|
||
| |
|
||
| MarkSlider |
|
||
|___________________________|[1K
|
||
|
||
# Hints: More tools
|
||
* JPEG to ascii: jp2a
|
||
MMMMMNNNNNMNkkk0MMWdll0MMMMMOc,,;cllc;,,
|
||
MMMMNNNNNMNOkOXMMKolkNMMW0ocdOXWMMMMMMWX
|
||
MMMNNNNNMNOkONMMkldNMMWx:dXMMMMWKOxxxOKW
|
||
MMWNNNNMWOkkNMMxlxWMMK;oWMMMXoloOXNWNXOd
|
||
MMNNNNWM0kkKMMOldMMM0,OMMMNclNMMMMM:WMMM
|
||
MWNNNNMNkkOWMNllNMMN,xMMMN'KMMMMMMM NMMM
|
||
MWNNNNMXkk0MM0ldMMMx,WMMM;kMMMMMMMW XMMM
|
||
MWNNNWMKkk0MMOlxMMMl:MMMM.NMMMMMMMO.xMMM
|
||
MWNNNNMXkk0MM0ldMMMx,WMMM;kMMMMMMN.; KMM
|
||
MWNNNNMNkkOWMNllNMMN,xMMMN'KMMMMK..,. 0M
|
||
MMNNNNWM0kkKMMOldMMM0,OMMMNclNMN:;NMW:;K
|
||
MMWNNNNMWOkkNMMxlxWMMK;oWMMMXoloOXNWNXOd
|
||
MMMNNNNNMNOkONMMkldNMMWx:dXMMMMWKOxxxOKW
|
||
MMMMNNNNNMNOkOXMMKolkNMMW0ocdOXWMMMMMMWX
|
||
MMMMMNNNNNMNkkkKMMWdll0MMMMMOc,,;cllc;,,
|