Skip to content

Instantly share code, notes, and snippets.

@karmab
Last active February 22, 2019 19:58
Show Gist options
  • Save karmab/88484526124ce5313040f3bf9a195c68 to your computer and use it in GitHub Desktop.
Save karmab/88484526124ce5313040f3bf9a195c68 to your computer and use it in GitHub Desktop.
demo_preparation

Basic tooling for cool demos

Installation

sh install.sh

How to use

demo.sh YOUR_SCRIPT > YOUR_SCRIPT_WITH_DEMO

then edit the generated script to put description of your tasks and you can then run your modified script as a demo

#!/bin/bash
if [ "$#" != "1" ] ; then
echo Usage: $0 script
exit 1
fi
echo \#!/bin/bash
echo
echo source `which util.sh`
echo
cat $1 | while read line ; do
line=`echo $line | sed 's/\"/\\\"/g'`
echo backtotop
echo desc \"\"
echo run \"$line\"
echo
done
#!/bin/bash
INSTALL="${INSTALL:-/usr/bin}"
mv util.sh $INSTALL
chmod 700 $INSTALL/util.sh
mv demo.sh $INSTALL
chmod 700 $INSTALL/demo.sh
if [ -d /Users ] ; then
brew install pv asciinema
else
mv pv.repo /etc/yum.repos.d
yum --nogpgcheck -y install pv asciinema
grep -q CentOS /etc/redhat-release && yum -y install epel-release && yum --nogpgcheck -y install asciinema
fi
which asciinema && asciinema auth
[ivarch]
name=RPMs from ivarch.com
baseurl=http://www.ivarch.com/programs/rpms/$basearch/
enabled=1
#!/bin/bash
readonly reset=$(tput sgr0)
readonly green=$(tput bold; tput setaf 2)
readonly yellow=$(tput bold; tput setaf 3)
readonly blue=$(tput bold; tput setaf 6)
function desc() {
maybe_first_prompt
echo "$blue# $@$reset"
prompt
}
function prompt() {
echo -n "$yellow\$ $reset"
}
started=""
function maybe_first_prompt() {
if [ -z "$started" ]; then
prompt
started=true
fi
}
function backtotop() {
clear
}
function run() {
maybe_first_prompt
rate=25
if [ -n "$DEMO_RUN_FAST" ]; then
rate=1000
fi
echo "$green$1$reset" | pv -qL $rate
if [ -n "$DEMO_RUN_FAST" ]; then
sleep 0.5
fi
eval "$1"
r=$?
read -d '' -t 1 -n 10000 # clear stdin
prompt
if [ -z "$DEMO_AUTO_RUN" ]; then
read -s
fi
return $r
}
function relative() {
for arg; do
echo "$(realpath $(dirname $(which $0)))/$arg" | sed "s|$(realpath $(pwd))|.|"
done
}
trap "echo" EXIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment