Git Product home page Git Product logo

demo-magic's Introduction

Demo Magic

demo-magic.sh is a handy shell script that enables you to script repeatable demos in a bash environment so you don't have to type as you present. Rather than trying to type commands when presenting you simply script them and let demo-magic.sh run them for you.

Features

  • Simulates typing. It looks like you are actually typing out commands
  • Allows you to actually run commands or pretend to do so.
  • Can hide commands from presentation. Useful for behind the scenes stuff that doesn't need to be shown.

Functions

pe

Print and Execute.

  1. Waits for you to press ENTER (unless -n is passed).
  2. Then simulates typing the command you gave it.
  3. Then pauses until you press ENTER.
  4. Then runs the command.
#!/bin/bash

pe "ls -l"

pei

Print and Execute immediately.

  1. Simulates typing the command you gave it.
  2. Then pauses until you press ENTER.
  3. Then runs the command.
#!/bin/bash

pei "ls -l"

p

Print only.

  1. Waits for you to press ENTER (unless -n is passed).
  2. Then simulates typing the command you gave it.
  3. Then pauses until you press ENTER.
#!/bin/bash

p "ls -l"

wait

Waits for the user to press ENTER.

If PROMPT_TIMEOUT is defined and > 0 the demo will automatically proceed after the amount of seconds has passed.

#!/bin/bash

# Will wait until user presses enter
PROMPT_TIMEOUT=0
wait

# Will wait max 5 seconds until user presses
PROMPT_TIMEOUT=5
wait

cmd

Enters script into interactive mode and allows newly typed commands to be executed within the script

#!/bin/bash

cmd

Getting Started

Create a shell script and include demo-magic.sh

#!/bin/bash

########################
# include the magic
########################
. demo-magic.sh

# hide the evidence
clear

# Put your stuff here

Then use the handy functions to run through your demo.

Handy Starting Points

There are a few samples in the samples/ folder to show you how easy it is to get up and running.

The demo-template.sh is a bit of a showcase of some of the features.

The remote-exec folder is there to show you how to run demo-magic locally and on a remote server via ssh. This was created in response to Issue #24

Command line usage

demo-magic.sh exposes some options to your script.

  • -d - disable simulated typing. Useful for debugging
  • -h - prints the usage text
  • -n - set no default waiting after p and pe functions
  • -w - set no wait timeout after p and pe functions
$ ./my-demo.sh -h

Usage: ./my-demo.sh [options]

  Where options is one or more of:
  -h  Prints Help text
  -d  Debug mode. Disables simulated typing
  -n  No wait
  -w  Waits max the given amount of seconds before proceeding with demo (e.g. `-w5`)

Useful Tricks

Faking network connections

Network connections during demos are often unreliable. Try and fake whatever commands would rely on a network connection. For example: Instead of trying to install node modules in a node.js application you can fake it. You can install the node_modules at home on your decent network. Then rename the directory and pretend to install it later by symlinking. If you want to be thorough you can capture the output of npm install into a log file then cat it out later to simulate the install.

#!/bin/bash

########################
# include the magic
########################
. demo-magic.sh

# hide the evidence
clear

# this command is typed and executed
pe "cd my-app"

# this command is merely typed. Not executed
p "npm install"

# this command runs behind the scenes
ln -s cached_node_modules node_modules

# cat out a log file that captures a previous successful node modules install
cat node-modules-install.log

# now type and run the command to start your app
pe "node index.js"

No waiting

The -n no wait option can be useful if you want to print and execute multiple commands.

# include demo-magic
. demo-magic.sh -n

# add multiple commands
pe 'git status'
pe 'git log --oneline --decorate -n 20'

However this will oblige you to define your waiting points manually e.g.

...
# define waiting points
pe 'git status'
pe 'git log --oneline --decorate -n 20'
wait
pe 'git pull'
pe 'git log --oneline --decorate -n 20'
wait

Pesky key cursor

Some terminals (Mac terminal, iterm2) display a key cursor when input is masked.

Pesky Key Icon

You can turn this off in iterm2 like so:

Disable icon in iterm2

demo-magic's People

Contributors

brightzheng100 avatar fu avatar furchin avatar necabo avatar nokome avatar noscript avatar paxtonhare avatar rdodev avatar smithjohntaylor avatar udondan avatar zvladar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

demo-magic's Issues

Questions on use

Two questions:

  1. Is there an easy way to turn off the bolding of the executed command lines?
  2. Can I get demo-magic to pause at an empty prompt instead of the prompt not being printed until I leave pause mode?

Navigate mode.

Hi ๐Ÿ‘‹

Thanks for this project! ๐Ÿป

For my demo purposes I changed your script drastically to more "navigate" like (interactive) mode. You can see the script here: https://gist.github.com/bwplotka/c2021c9411ac10cc45ff24aa0e32837a

The goal for me was to be able to fast forward and fast backward any time during the demo. There are numerous cases like:

  • Commands needs to be retried suddenly
  • Someone from audience wants to reply some bit of demo
  • I want to show something in detail
    .. and probably more.

I am adding this issue to ask if you want to support such cases in your project? Would you like to add this script here? I could host it in my own github repo, but since the code and idea is inspired by your bash code, I am happy to contribute it here if you obviously want such contribution.

Note I am not bash master, it that does not allow flexible options and probably does not work across all, gazillion shell versions and distros etc etc (: So it would need some touches.

Cheers!

Support passing command prefix to cmd

I think it would be neat if cmd could simulate typing the beginning of the command.
For instance:

pe "htop"
# Copy-paste some pid
cmd "kill "
# wait for enter key like p, pe etc.
# simulates typing kill
# presenter pastes the pid and presses return to execute

Also, if you forgot you were on the cmd step, you don't accidentally end up executing an empty command while you were trying to trigger the next step. Instead you trigger something which has a visual feedback. I think this is better in terms of UX.

Suggestion command for print+eval+nowait

Thanks for the cool script.

I wanted a few commands to execute directly. The suggested option in the Readme using wait however causes the cursor on my shell to jump to the next line without prompt. This breaks the illusion of me typing. Also I didn't really like that I had to put a wait after each command when I wanted to opt in for NO_WAIT. Hence I defined a function:

# print and execute immediately
function pei {
    NO_WAIT=true pe $1
}

# usage
pei "cd agilebank" 

What do you think, could this be a nice addition? I'm happy to provide a pull request with updated docs.

Support multi-line commands

First, this is really awesome.

One thing I'd like to be added. Often, a multi-line CLI shows better. Instead of one long line I prefer it like this:

sls stackstorm docker run \ 
 --verbose \ 
 --function InviteSlack \ 
 --data 
 '{"body": {"first_name": "Donald", "email": "[email protected]"}}'

I put in a quick hack that works for my demo:

function pe() {
  # print the command
  p "$@"

  # Clean from \n and \
  c=${@//"\n"/}
  c=${c//\\/}

  # execute the command
  eval "$c"
}

But it will eat \ symbols in some commands so not good enough for a PR.
So take this as an input.

Thanks again for an awesome tool!

Use Oh-My-Zsh theme for the prompt during the demo

I want to use the same Oh-My-Zsh theme of the prompt in my terminal during the demo too. In particular, I'm using Agnoster theme, that use some nested functions for defining $PROMPT, so it seems it's not enough assigning the value of this variable to $DEMO_PROMPT. Someone can help me?

How to execute eval?

Hi, how can I auto print this eval "$(curl -sL check.vapor.sh)" and run upon enter?

I'm using zsh but i tried this and iTerm is printing the shell of vapor.sh it seems...

#!/usr/bin/env bash

########################
# include the magic
########################
. demo-magic.sh

########################
# Configure the options
########################

DEMO_PROMPT="${GREEN}โžœ ${CYAN}\W "

# hide the evidence
clear

# Put your stuff here
p "eval \"$(curl -sL check.vapor.sh)\""

Keep default prompt

Is there a way to keep my default prompt between each step?

I've tried the following in my script but it results in now prompt at all:

. ~/demo-magic.sh
DEMO_PROMPT="${PS1}"
pe "ls -l"
pe "echo 'Hello'"

Issue with wait not respected

Using demo-magic on my machine (OSX with zsh or bash) won't respect NO_WAIT, i.e. it will always directly run the commands without waiting for pressing return.

I think the issue is here:

if [[ ! $NO_WAIT ]]; then

This does not test for a boolean true or false expression but whether the variable is set.
Explanation from here:

So, basically [ $foo ] will be true if $foo is non-empty. Not true or false, just non-empty. [ ! $foo ] is true if $foo is empty or undefined.

My workaround for now is unset NO_WAIT which then works as expected with the current implementation.

Control-C

How do you code control-c so the pe interpreter will understand it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.