WP-CLI live presentation, like a pro

I recently gave a talk about WP-CLI at WordCamp Israel 2016. I thought it would be interesting to actually demo WP-CLI in real time, rather than use boring slides.

I used OS X split screen mode, with a terminal window on one side, and a browser on the other showing the site I’m creating and editing:

The tricky part was to not have to type the commands I wanted to demo (which would be boring, and slow). Luckily, I’ve found doitlive, which takes a bash script and types the commands in a simulated window.

By default doitlive echos the characters one by one: the presenter just has to type randomly on his keyboard (like a Madman!).

But I wanted to be able to move on stage, and control the presentation using a remote. So I set doitlive’s speed option to a large number, and each command appeared with a single key press. I still needed a return to execute the command, a key not present on my remote. I worked around this by using TextExpander to replace ‘b’ (from the ‘Black Screen’ button) with a newline.

The result: each command required just two button presses. (The truth: I forgot to turn on TextExpander,  so I had to go back to the lectern for every single command. Bah.)

Some tips that might help if you’re planning to do something similar:

  • Use the `-g` param when opening a url in the browser to keep the focus on the terminal window
  • Write a cleanup/prep script that sets up your environment the way you need it before the demo (empty the db, delete or rename files, etc)
  • Rehearse. A lot. This is true for every presentation, but is a must with live demos.

Here’s the script I’ve used, split into commented sections. I’ll link to the video once it’s up on WordPress.tv.

[code lang=”bash” title=”doitlive config”]
#doitlive shell: /bin/bash
#doitlive prompt: l33t {r_angle.red}{r_angle.yellow}{r_angle.green}
#doitlive commentecho: true
#doitlive speed: 1000
[/code]

[code lang=”bash” firstline=”5″ title=”Intro, using ascii art files”]
cat name.txt
cat wp-cli.txt
open http://wp-cli.org -g
clear
[/code]

[code lang=”bash” firstline=”9″ title=”Demo site and WP-CLI download and setup”]

open http://wpcli.dev -g

#Download
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

# Permission and move to path as ‘wp’
chmod +x wp-cli.phar

sudo mv wp-cli.phar /usr/local/bin/wp

# Test
wp –info
wp
[/code]

[code lang=”bash” firstline=”22″ title=”Cleanup before we start”]
cd mdocs
mv index.html index.old
clear
[/code]

[code lang=”bash” firstline=”25″ title=”Core download and installation”]

wp core download

ls -l

open http://wpcli.dev -g

wp core config –dbname=wpcli –dbuser=root –dbpass=root –dbhost=localhost –dbprefix=wpcli_

cat wp-config.php

wp core install –url=”http://wpcli.dev” –title=”WP-CLI Demo” –admin_user=yoav –admin_password=mypassword –admin_email=yoav@farhi.org

open http://wpcli.dev -g
[/code]

[code lang=”bash” firstline=”38″ title=”Language packs and updates”]

wp core language install he_IL –activate

open http://wpcli.dev -g

wp core update

wp core language activate en_US

clear
[/code]

[code lang=”bash” firstline=”47″ title=”Options”]
wp option update blogname “l33t wp-cli demo”

open http://wpcli.dev -g

clear
[/code]

[code lang=”bash” firstline=”52″ title=”Packages”]
wp package install aaemnnosttv/wp-cli-http-command

wp package list

clear
[/code]

[code lang=”bash” firstline=”57″ title=”Import theme unit test data”]
wp http get https://wpcom-themes.svn.automattic.com/demo/theme-unit-test-data.xml –scheme=https > theme-unit-test-data.xml

wp import theme-unit-test-data.xml –authors=create

wp plugin install wordpress-importer –activate

wp import theme-unit-test-data.xml –authors=create –skip=attachment

open http://wpcli.dev -g

clear
[/code]

[code lang=”bash” firstline=”68″ title=”Options using json format”]
wp option get sticky_posts

wp option update sticky_posts [] –format=json

open http://wpcli.dev -g

clear
[/code]

[code lang=”bash” firstline=”75″ title=”wp post generate”]
wp post generate –count=2

open http://wpcli.dev -g

clear

wp http get http://loripsum.net/api/5 | wp post generate –post_content –count=1

open http://wpcli.dev -g
[/code]

[code lang=”bash” firstline=”84″ title=”wp search-replace”]
wp search-replace Lorem WordPress

open http://wpcli.dev -g

clear
[/code]

[code lang=”bash” firstline=”89″ title=”wp scaffold”]

wp scaffold child-theme wpcli-child –parent_theme=twentysixteen –author=”Yoav Farhi” –author_uri=http://yoav.fr –activate

ls -l wp-content/themes/

ls -l wp-content/themes/wpcli-child

cat wp-content/themes/wpcli-child/style.css

open http://wpcli.dev -g

wp scaffold _s wpcli_s –theme_name=wpcli-s –author=”Yoav Farhi” –sassify –activate

ls -l wp-content/themes/

ls -l wp-content/themes/wpcli_s
[/code]

[code lang=”bash” firstline=”104″ title=”wp theme”]
wp theme list

wp theme activate twentyfourteen

open http://wpcli.dev -g

clear
[/code]

[code lang=”bash” firstline=”111″ title=”wp plugin and custom plugin commands”]
# wp plugin

wp plugin list

wp plugin install jetpack –activate

wp jetpack

wp jetpack module list

clear
[/code]

[code lang=”bash” firstline=”122″ title=”wp export/db”]
wp export

wp db export l33t-backup.sql

clear
[/code]

[code lang=”bash” firstline=”127″ title=”multisite”]
wp core multisite-convert

mv ms-rewrite-rules.txt .htaccess

wp site create –slug=msdemo

open http://wpcli.dev/msdemo -g

wp theme activate twentyfifteen –url=http://wpcli.dev/msdemo

open http://wpcli.dev/msdemo -g

clear
[/code]

[code lang=”bash” firstline=”140″ title=”custom commands”]
nano example-command.php

mkdir wp-content/mu-plugins
cp example-command.php wp-content/mu-plugins/

wp example hello “Wordcamp Israel 2016″

clear
[/code]

[code lang=”bash” firstline=”148″ title=”wrap up”]
cd ../

cat thankyou.txt

# Thanks for following! Questions?
# Typed using doitlive http://doitlive.readthedocs.org/
[/code]

Download the full script.

Leave a Reply

%d bloggers like this: