Created
July 27, 2012 18:18
-
-
Save gfixler/3189547 to your computer and use it in GitHub Desktop.
Vim: Show-And-Shell - simple, shell session playback
This file contains 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
" SHOW-AND-SHELL | |
" An *extremely* simplistic shell 'simulator'. | |
" Allows for copying a shell session into vim, | |
" marking up 'typed' sections, then stepping | |
" through a simulation of using the shell with | |
" a single key. Useful for didactic demos. | |
" | |
" Usage: | |
" Load or create a ShowShell file. | |
" Run :ShowShell_setup() | |
" - demo opens in a split | |
" (<C-w>o to close all other splits) | |
" Use F3 to step through the demonstration. | |
" - or remap it (last line of the script) | |
" - step count displayed in status area | |
" | |
" Format: | |
" * first 2 characters define manual/auto chars | |
" - use these to wrap 'manual' sections | |
" - must be first 2 characters in file | |
" - pick 2 chars not used in the file | |
" - these chars will never appear in the demo | |
" * demo begins in auto mode at character 3 | |
" | |
" Example: | |
" <>prompt: <ls> | |
" bar.foo | |
" fileA.ext | |
" fileB.ext | |
" fileC.ext | |
" foo.bar | |
" prompt: <rm file*.*> | |
" prompt: <ls> | |
" bar.foo | |
" foo.bar | |
" prompt: | |
function! ShowShell_setup () | |
let g:showsh = join(getline(0,'$'), "\n") | |
let g:showsh_step = 0 | |
let g:showsh_manual = g:showsh[0] | |
let g:showsh_auto = g:showsh[1] | |
let g:showsh = g:showsh[2:] | |
let g:showsh_autoing = 1 | |
new | |
norm i | |
call ShowShell_next() | |
endfunction | |
function! ShowShell_next () | |
if len(g:showsh) | |
let g:showsh_step += 1 | |
endif | |
echo g:showsh_step | |
while index([g:showsh_auto, g:showsh_manual], g:showsh[0]) >= 0 | |
let g:showsh_autoing = g:showsh[0] == g:showsh_auto | |
let g:showsh = g:showsh[1:] | |
endwhile | |
if g:showsh_autoing | |
while index([g:showsh_auto, g:showsh_manual], g:showsh[0]) < 0 | |
if !len(g:showsh) | |
return | |
endif | |
let @" = g:showsh[0] | |
call setreg('@"', getreg('@'), 'v') | |
norm G$PG$ | |
let g:showsh = g:showsh[1:] | |
endwhile | |
else | |
let @" = g:showsh[0] | |
call setreg('@"', getreg('@"'), 'v') | |
norm G$PG$ | |
let g:showsh = g:showsh[1:] | |
endif | |
endfunction | |
nnoremap <F3> :call ShowShell_next()<CR> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment