if !exists("g:screen_windowname") let g:screen_windowname = "" let g:screen_sessionname = "" endif function! Screen_Vars() if g:screen_sessionname == "" let tmp = system("screen -ls | awk '/Attached/ {print $1}'") let g:screen_sessionname = substitute(tmp, '\n', '', 'g') endif if g:screen_windowname == "" let g:screen_windowname = input("window name: ", g:screen_windowname) endif endfunction function! s:Screen_Cmd(cmd) call Screen_Vars() let cmd = "screen -S " . g:screen_sessionname . " -p " . g:screen_windowname . " -X " . a:cmd call system( cmd ) endfunction function! s:Screen_Send() call s:Screen_Cmd("readbuf /tmp/vim_buffer") call s:Screen_Cmd("paste . ") endfunction function! s:Screen_Session_Names(A,L,P) return system("screen -ls | awk '/Attached/ {print $1}'") endfunction function! s:Screen_Repl_Extra(lis) if stridx(g:screen_windowname, "py") == 0 return a:lis + ["\n"] endif return a:lis endfunction function! Screen_Push_Register(reg) call writefile( s:Screen_Repl_Extra(split(strtrans(getreg(a:reg)), '\^@')), "/tmp/vim_buffer") call s:Screen_Send() echo "All done" endfunction function! Screen_Exec(fl,ll) range call writefile( getline(a:fl, a:ll), "/tmp/vim_buffer") call s:Screen_Send() endfunction command! -range -nargs=0 S call Screen_Exec(,) function! Screen_Toggle() if g:screen_top_size == 10 call Screen_Size( 60 ) else call Screen_Size( 10 ) endif endfunction command! -nargs=0 Screentoggle call Screen_Toggle() function! Screen_Size(size) let g:screen_top_size = a:size call s:Screen_Cmd("resize " . a:size ) endfunction command! -nargs=1 SS call Screen_Size() function! Screen_Repl_Setup(new) let g:screen_windowname = a:new call s:Screen_Cmd("split") call Screen_Size( 60 ) call s:Screen_Cmd("focus") call s:Screen_Cmd("select ". a:new) call s:Screen_Cmd("focus") call s:Screen_Cmd("select vim") endfunction function! Screen_Repl(new) call s:Screen_Cmd("focus") if a:new == "n" " XXX we need the number of the new screen call s:Screen_Cmd("screen") call s:Screen_Cmd("number " . g:screen_windowname) else let g:screen_windowname = a:new call s:Screen_Cmd("select " . a:new) endif call s:Screen_Cmd("focus") endfunction command! -nargs=* SR call Screen_Repl() function! Screen_Cap(...) let file = "/tmp/screen-copy-capture" call s:Screen_Cmd("focus") call s:Screen_Cmd("hardcopy " . file ) call s:Screen_Cmd("focus") if (a:0) if str2nr(a:1) exec "read ! tail -n " . a:1 . " " . file else exec "read ! grep -i " . a:1 . " " . file endif else exec "read " . file endif endfunction command! -nargs=? SC call Screen_Cap()