Last active
December 19, 2024 09:58
-
-
Save danielroedl/7515f448c928497905b1a01d0f0bbf70 to your computer and use it in GitHub Desktop.
Template for code presentation with vim and tmux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# - install tmux and vim (e.g. for ubuntu run `apt install tmux vim`) | |
# - Create the showroom.presentation.sh | |
# - add executable flag with `chmod +x showroom.presentation.sh` | |
# - To run the presentation | |
# - Open a terminal and run `./showroom.presentation.sh` | |
# - Open a second terminal on presentation screen and run `tmux a -t showroom` | |
# - Go back to the first terminal and hit [Space] to send next line | |
# - To stop the presentation hit ':q' in vim | |
# | |
# Try it out | |
chmod +x showroom.presentation.sh | |
./showroom.presentation.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Script for code presentation with vim and tmux | |
# | |
# This script can be used to present several commands | |
# in a presentation without having typo issues when typing | |
# in the commands manually. | |
# | |
# | |
# Configuration | |
TMUX_PRESENTER_SESSION_NAME=showroom | |
tmux_config() { | |
# Turn status bar off | |
tmux set-option -t ${TMUX_PRESENTER_SESSION_NAME} status off | |
# Use bash as shell | |
tmux set-option -t ${TMUX_PRESENTER_SESSION_NAME} set -g default-shell /bin/bash | |
} | |
setup_panes() { | |
# Do the pane setup here | |
# e.g. an initialze basic grid with 2 terminals in horizontal layout | |
tmux split-pane -t ${TMUX_PRESENTER_SESSION_NAME} | |
} | |
# Start of script | |
if tmux list-sessions | grep ${TMUX_PRESENTER_SESSION_NAME} 2>&1 >/dev/null; then | |
# Remove running tmux session | |
echo "Kill existing session ${TMUX_PRESENTER_SESSION_NAME}" | |
tmux kill-session -t ${TMUX_PRESENTER_SESSION_NAME} | |
fi | |
echo "Create new session ${TMUX_PRESENTER_SESSION_NAME}" | |
tmux new -d -s ${TMUX_PRESENTER_SESSION_NAME} | |
tmux_config | |
setup_panes | |
# Echo hint for user | |
echo -e "\nConnect in a terminal to session with 'tmux a -t ${TMUX_PRESENTER_SESSION_NAME}'" | |
echo "[RETURN] to open presentation file..." | |
read ret | |
# Get line to start and open this file in vim | |
START=$(grep -ne "# START" $0 | tail -n 1 | cut -d: -f1) | |
# Add Space command to temp vimrc | |
tmp_vimrc=$(mktemp) | |
cat ~/.vimrc 2>/dev/null >$tmp_vimrc | |
echo "map <Space> :exe '!tmux send -t ${TMUX_PRESENTER_SESSION_NAME}:0.'.getline('.')<CR><CR><down>" >>$tmp_vimrc | |
vim -Nu $tmp_vimrc +$(($START + 1)) $0 | |
# End of the presentation | |
tmux kill-session -t ${TMUX_PRESENTER_SESSION_NAME} | |
exit | |
# ------------------------------------------------------------------- | |
# PRESENTATION PART | |
# ------------------------------------------------------------------- | |
# All lines below this comment block are part of the presentation. | |
# | |
# - Every line is send to the tmux session. Pattern is: | |
# <terminal> "<the command>" Enter | |
# - Put the 'Enter' at the end to a seperate line if the command should be | |
# shown in the first place and than be executed | |
# - To send Ctrl+C to a terminal use 'C-c' | |
# | |
# Place the cursor on a line and hit <SPACE> to send the line. To skip | |
# lines (e.g. comments for the presenter) just move cursor down. | |
# | |
# START - This line indicates the start of the presentation - DO NOT DELETE | |
0 "echo 'test'" Enter | |
1 "while true; do date; sleep 1; done" | |
# A comment for the presenter - skip it | |
1 Enter | |
0 "echo 'I will now end the loop in the other terminal'" Enter | |
1 C-c | |
1 "\# Just a comment for the terminal" | |
0 "echo 'Now we remove the comment below'" Enter | |
1 C-u | |
0 "Comments that should not appear in the terminals can be done like this..." C-u |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment