#!/bin/bash function repeatChar() { local length=$1; shift local char="$1"; shift local res="" # echo repeatChar len=${length} char=\"${char}\" 1>&2 local i for ((i=0;i<$length;i++)); do res="${res}${char}" #echo res=\"${res}\" 1>&2 #res="${res:0:$i}${char}" #echo res=\"${res}\" 1>&2 done echo -en "${res}" } function topLine() { local l local f="(($width-2))" l="+" l+=$(repeatChar $(($width-2)) "-") l+="+" echo ${l} } function bodyLine() { spaces="$(repeatChar $((width-2)) " ")" echo "|${spaces}|" } function emptySlide() { local i line f local oldifs="${IFS}" IFS='' slide=() curposx=0 curposy=0 for ((i = 0 ; i < $height ; i++ )); do if ((i==0 || i==$((height-1)))); then line=$(topLine) else line=$(bodyLine) fi line+="\n" # echo line now $line 1>&2 slide+=($line) done IFS="${oldifs}" #declare -p slide } function putWord() { local x=$1; shift local y=$1; shift local c="$1"; shift local l=${#c} local e=$((x+l)) # echo x=$x y=$y c=$c l=$l e=$e start=${slide[$y]} slide[$y]="${slide[$y]:0:$x}${c}${slide[$y]:$e}" } function putString() { local c="$1"; shift local l=${#c} putWord $curposx $curposy "$c" curposx=$((curposx+l)) } function putLines() { local x=$1; shift local y=$1; shift local line = $1; shift while [[ -n "$line" ]] ; do putWord $x $y "${line}" y=$((y+1)) line=$1; shift done } function putBullets() { local x=$1; shift local y=$1; shift local line=$1; shift while [[ -n "$line" ]] ; do putWord $x $y "* ${line}" y=$((y+1)) line=$1; shift done } function wrapText() { local c="$1"; shift local w="$1"; shift local line="" local i=0 for word in $c; do local l=${#word} local ll=${#line} if ((l+ll>w)); then echo $line line="" fi line="${line}$word " done echo $line } function putText() { local c="$1"; shift local x="$1"; shift local y="$1"; shift local w="$1"; shift local lines mapfile -t lines < <(wrapText "$c" $w) # Removes newlines #declare -p lines local line for line in "${lines[@]}"; do putWord $x $y "$line" y=$((y+1)) done } function waitForAnyKey() { local key read -n 1 -s -r -p "" key echo "${key}" } function show() { local line datei datei=`printf "slides/slide-%02d.txt" "${slideNr}"` centeredText $((height-2)) "<${slideNr}>" echo -en "" > ${datei} for line in "${slide[@]}"; do echo -en "$line" echo -en "$line" >> ${datei} done slideNr=$(($slideNr+1)) } function box() { local x=$1; shift local y=$1; shift local w=$1; shift local h=$1; shift local i putWord $x $y "+" putWord $((x+w-1)) $y "+" putWord $((x+w-1)) $((y+h-1)) "+" putWord $x $((y+h-1)) "+" putWord $((x+1)) $y $(repeatChar $((w-2)) "-") putWord $((x+1)) $((y+h-1)) $(repeatChar $((w-2)) "-") for ((i=y+1;i| ' show emptySlide centeredBox 3 'Working directory' putBullets 4 6 'Aktuelles Verzeichnis, Kommando pwd' putWord 6 8 'Dateiangaben beziehen sich auf dieses Verzeichnis' putWord 6 10 '... und auch Verzeichnisangaben' show emptySlide centeredBox 3 'Befehl und Argumente' putBullets 4 6 'Getrennt durch **Leerschläge**' 'Erstes «Wort» ist der Befehl/Programm' 'Alle weiteren Wörter sind Argumente' putWord 4 10 'Typische Argumente:' putBullets 4 11 'Switches (mit einfachen oder doppelten Minuszeichen)' 'Input-Datei(en)' 'Output-Datei' show emptySlide centeredBox 3 'Beispiele' putBullets 4 6 'cat slides/slides-01.txt' 'ls -l' 'pwd' 'cd slides' 'cd ..' 'code slides.bash' show emptySlide centeredBox 3 'Wildcards' putBullets 4 6 'Viele Dateien auf einmal mit Mustern beschreiben' '*.txt Alle Dateien, dit mit .txt enden' \ 'Der Stern steht für beliebig viele Zeichen (auch 0)'\ 'Das Fragezeichen ? steht für genau ein Zeichen'\ 'Ein Auswahl von Zeichen [234] (genau eines)'\ 'Eine Auswahl von Wörtern {bli,bla,blu} (genau eines)'\ 'Eine Sequenz {05..12}' emptySlide centeredBox 3 'Input/Output' putBullets 4 6 'Normalfall: Input vom und Output aufs Terminal' 'Verknüpfung von Programmen' \ ' bash slides.bash | sort' 'Output in Datei' ' bash slides.bash > allSlides.txt' \ 'Input von Datei' ' sort < allSlides.txt' show emptySlide centeredBox 3 'Tasten' putBullets 4 6 'Tabulator (Vervollständigung)' 'Pfeiltaste nach oben holt letztes Kommando' 'Ctrl-C stoppt Programm' show emptySlide centeredBox 5 'Your turn!' putBullets 4 8 'Installation der Software' 'Working directory (wo bin ich)' 'Viel Spass!' show