First version of presentation script
This commit is contained in:
parent
9359d1c9f7
commit
66e7b60ad7
24
README.md
24
README.md
@ -1,2 +1,24 @@
|
||||
# ScriptedPresentation
|
||||
# ScriptedPresenter
|
||||
|
||||
Stop copying and pasting commands during presentations. Use this template.
|
||||
|
||||
## Requirements
|
||||
|
||||
* tmux 2.3 or greater
|
||||
* bash
|
||||
* a terminal
|
||||
* something to present
|
||||
* (optional) someone to listen
|
||||
|
||||
## How to Use
|
||||
|
||||
* Clone this repo
|
||||
* Fill in the blanks to run your commands
|
||||
* Run `./demo.sh` from outside tmux
|
||||
* Press <enter> to advance to next command
|
||||
|
||||
## How to Contribute
|
||||
|
||||
This template isn't perfect, and there are a lot of people that know bash better
|
||||
than me. If you find a way to accomplish something in this script more
|
||||
efficiently, easily, or correctly, please send a pull request.
|
||||
|
111
presentation.sh
Executable file
111
presentation.sh
Executable file
@ -0,0 +1,111 @@
|
||||
#!/bin/bash
|
||||
|
||||
GREEN='\033[0;32m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m'
|
||||
|
||||
# Name of the tmux session we'll create and run from
|
||||
session="demo_sess"
|
||||
main_win="demo"
|
||||
|
||||
function has-session {
|
||||
tmux has-session -t "${1}" 2>/dev/null
|
||||
}
|
||||
|
||||
# If we aren't in the demo session, create it and enter.
|
||||
# You can also use this to do environment setup in the session.
|
||||
if [ "$DEMOSESSION" == "" ]; then
|
||||
if has-session "${session}"; then
|
||||
echo "Killing old session..."
|
||||
tmux kill-session -t ${session}
|
||||
fi
|
||||
|
||||
tmux new-session -s "${session}" -n "${main_win}" -c $(pwd) -d
|
||||
tmux send-keys -t "${session}" 'export DEMOSESSION=1' C-m
|
||||
tmux send-keys -t "${session}" 'clear' C-m
|
||||
tmux send-keys -t "${session}" './presentation.sh' C-m
|
||||
exec tmux attach -t "${session}"
|
||||
fi
|
||||
|
||||
# prompt prints the provided message and waits for <enter>
|
||||
function prompt() {
|
||||
printf "${GREEN}${1}${NC}"
|
||||
read -p ""
|
||||
}
|
||||
|
||||
# wait_and_prompt first prints "...Done" to indicate the previous command has
|
||||
# finished, then waits for <enter> before calling prompt.
|
||||
function wait_and_prompt() {
|
||||
printf "${GREEN}...Done${NC}"
|
||||
read -p ""
|
||||
|
||||
clear
|
||||
prompt "${1}"
|
||||
}
|
||||
|
||||
# run displays the command about to be run, waits for <enter>, then runs the
|
||||
# command in the current tmux pane.
|
||||
function run() {
|
||||
printf "\n\$ ${BLUE}${*}${NC}"
|
||||
read -p ""
|
||||
${*}
|
||||
}
|
||||
|
||||
# run_below creates a new tmux pane below the current one and executes a command
|
||||
# in it. The first argument indicates the pane size, for example "-l 20" means
|
||||
# 20 lines tall, or "-p 20" means 20 percent of the window. The second argument
|
||||
# is the command to run.
|
||||
#
|
||||
# Note: When the command terminates the pane will close!
|
||||
function run_below() {
|
||||
size_flags=${1}
|
||||
command=${2}
|
||||
|
||||
tmux split-window -d -v -t "${session}" ${size_flags} "${command}"
|
||||
}
|
||||
|
||||
# run_beside behaves exactly like run_below except the pane is created to the
|
||||
# right of the current pane, rather than below it.
|
||||
function run_beside() {
|
||||
size_flags=${1}
|
||||
command=${2}
|
||||
|
||||
tmux split-window -d -h -t "${session}" ${size_flags} "${command}"
|
||||
}
|
||||
|
||||
function run_background() {
|
||||
window_name=${1}
|
||||
command=${2}
|
||||
|
||||
tmux new-window -d -n "${window_name}" -t "${session}" "${command}"
|
||||
}
|
||||
|
||||
# focus_last switches to the last pane that was in focus. Useful if you start a
|
||||
# new window or pane without providing the -d option.
|
||||
function focus_last() {
|
||||
tmux last-pane -t "${session}"
|
||||
}
|
||||
|
||||
# terminate kills the tmux session and all contained windows, panes, commands
|
||||
# running, etc.
|
||||
function terminate() {
|
||||
tmux kill-session -t "${session}"
|
||||
}
|
||||
|
||||
prompt "This is the first step, no need to wait here"
|
||||
run echo "Hello World"
|
||||
|
||||
wait_and_prompt "First command done, moving on to the second one"
|
||||
run echo "Example command number two"
|
||||
|
||||
wait_and_prompt "Let's start a ping down below..."
|
||||
run_below "-l 10" "ping localhost"
|
||||
|
||||
wait_and_prompt "Now open a ping in a new window, but don't show that window"
|
||||
run_background "win-name" "ping localhost"
|
||||
|
||||
wait_and_prompt "Finally, run a ping next to this"
|
||||
run_beside "-p 30" "ping localhost"
|
||||
|
||||
wait_and_prompt "Pressing enter one more time will kill the whole demo"
|
||||
terminate
|
Loading…
Reference in New Issue
Block a user