Permalink
Browse files

added scripts from OSCON lightning talk

  • Loading branch information...
1 parent 2740707 commit f9af476ae1f224e58b675319a2e040b8a3d30c8e @xdg xdg committed Jul 20, 2012
Showing with 82 additions and 0 deletions.
  1. +77 −0 scripted-screencast.pl
  2. +5 −0 test-script.sh
View
@@ -0,0 +1,77 @@
+#!/usr/bin/env perl
+use v5.10;
+use strict;
+use warnings;
+use autodie;
+
+# stuff we need
+use Cwd qw/getcwd/;
+use File::Slurp qw/read_file/;
+use IO::Prompt qw/prompt hand_print/;
+use Term::ANSIColor qw/colored/;
+STDOUT->autoflush(1);
+STDERR->autoflush(1);
+
+# get command arguments and static data
+my ( $file, $video, @rec_options ) = @ARGV;
+unless ( defined($file) && defined($video) && -r $file ) {
+ die "Usage: $0 <shell-file> <video-output-file>\n";
+}
+my $hostname = `hostname`;
+chomp $hostname;
+
+# fork screen recorder to background
+if ( my $pid = fork ) { # parent
+
+ # setup
+ local $SIG{INT} = sub { kill 15, $pid; wait; exit };
+ 1 until prompt( "Type 'start' to start\n", -w => 'start', '-tty' );
+ system("clear");
+
+ # iterate commands
+ for my $cmd ( read_file( $file, { chomp => 1 } ) ) {
+
+ # ignore comments
+ next if $cmd =~ /^#/;
+
+ # fake a prompt and typing
+ print cmd_prompt();
+ prompt( -echo => '', -nl => '', '-tty' );
+ hand_print( { -speed => 0.25 }, "$cmd" );
+ prompt( -echo => '', -nl => '', '-tty' );
+ say '';
+
+ # special case chdir or pass through to system
+ if ( $cmd =~ /^cd (.*)/ ) {
+ chdir $1;
+ }
+ else {
+ system($cmd);
+ }
+ }
+
+ # teardown
+ print cmd_prompt();
+ prompt('-tty');
+ say "Ending recording; please wait for recorder to shut down...";
+ kill 15, $pid;
+ wait;
+ say "Done";
+}
+else { # child
+ open STDIN, "<", "/dev/null";
+ open STDOUT, ">", "/dev/null";
+ open STDERR, ">", "/dev/null";
+ exec("recordmydesktop -o $video --on-the-fly-encoding @rec_options");
+}
+
+# fake my personal command prompt
+sub cmd_prompt {
+ my $error = shift;
+ ( my $cwd = getcwd ) =~ s/\Q$ENV{HOME}\E/~/;
+ return
+ colored( "", $error ? 'bold red' : 'bold green' ) . " ["
+ . colored( "david\@$hostname", 'cyan' ) . "] "
+ . $cwd . "\n\$ ";
+}
+
View
@@ -0,0 +1,5 @@
+#!/bin/sh
+ls
+less test-script.sh
+perl -wE 'say "Hello World"'
+echo "That's it"

0 comments on commit f9af476

Please sign in to comment.