#!/bin/sh -e # gen-demo.sh: an automated way of creating an example session recording # # Prerequisites: # - the parent shell has sdn installed, # - https://git.janouch.name/p/liberty tools/wdye is in PATH. checkout=/tmp/sdn if [ -d "$checkout/.git" ] then git -C "$checkout" reset --hard git -C "$checkout" clean -fdx else git clone https://git.janouch.name/p/sdn.git "$checkout" fi WDYE_LOGGING=1 wdye /dev/stdin <<'LUA' for k, v in pairs(wdye) do _G[k] = v end local checkout = "/tmp/sdn" local shell = spawn { os.getenv "SHELL", "-c", 'cd -- "$1" && exec "$SHELL"', "gen-demo.sh", checkout, environ = {TERM="xterm-256color", SHLVL=false}, } assert(shell, "failed to spawn the user's shell") local function pause(seconds) expect(timeout {seconds}, shell:eof {function () error "shell exited prematurely" end}) end local function key(sequence) assert(sequence, "terminal does not define a required key") shell:send(sequence) pause(.75) end local function tap(sequence) assert(sequence, "terminal does not define a required key") shell:send(sequence) pause(.375) end local function type(text) for i = 1, #text do shell:send(text:sub(i, i)) if i < #text then pause(.125) end end pause(.75) end local enter = "\r" local meta_o = "\27o" local meta_t = "\27t" -- Let the shell finish drawing its initial prompt, then open sdn. pause(.5) key(meta_o) -- Toggle hidden entries, unnest one level, calculate directory sizes, nest. key "." key "." key "]" key "\0" pause(.25) key "[" -- Find NEWS through sdn, create ChangeLog -> NEWS, then show the new symlink. key(meta_o) type "ln -s " key(meta_o) key "s" type "NE" key(enter) type "ChangeLog" key(enter) key(meta_o) -- Exercise both viewers and the editor on a file near the bottom. tap "G" tap(shell.term.key_up) key(shell.term.key_up) key(shell.term.key_f3) key "q" key(shell.term.key_f15) key "q" key(shell.term.key_f4) type ":q" key(enter) -- Select all C++ sources in sdn and insert them into a shell command. key(meta_o) type "wc -l " key(meta_o) key "+" type "*.cpp" key(enter) key "t" key(enter) pause(.5) key(meta_o) -- Return to sdn, cycle through every sort column, and toggle the full view. for _ = 1, 6 do tap ">" end pause(.25) key(meta_t) key(meta_t) key(meta_o) shell:send "\4" expect(shell:eof {true}, timeout {5, function () error "shell did not exit after C-d" end}) local status = shell:wait() assert(status == 0, "shell exited abnormally: " .. status) LUA