summaryrefslogtreecommitdiffstats
path: root/Cancer/bridge/share/vim/vimfiles/plugin/bridge.vim
blob: 91f072d108b372307f0df1fa003b41226cd08642 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
" /vim/bridge.vim

if ! exists('s:bridge_name')
  let s:bridge_name = ""
endif

fun! Bridge_complete(A,L,P)
    let a = strpart(a:A,0,a:P)
    return split(system("bridge list \"".a.".*\""), "\n")
endfun

fun! Bridge_status()
  if s:bridge_name == ""
    return "Disconnected"
  else
    return "Connected to " . s:bridge_name
  else
  endif
endfun

setlocal statusline=%<%f\ \(%{Bridge_status()}\)\ %h%m%r%=%-14.(%l,%c%V%)\ %P\ of\ %L\ \(%.45{getcwd()}\)

fun! Bridge_display()
  if s:bridge_name == ""
    echo "Not connected!"
    return
  endif
  let cmd = "bridge attach ".s:bridge_name
  silent exe "!" . cmd
  redraw!
endfun

fun! Bridge_connect()
  if s:bridge_name == ""
    let m = "boot new"
  else
    let m = s:bridge_name
  endif
  let name = input("Connect to [".m."]: ", "", "customlist,Bridge_complete")
  if name == ""
    if s:bridge_name != ''
      " stay connected
      echo
      return
    endif
    let system = input("Command: ", "")
    if system == ""
        echo "Aborted!"
	return
    endif
    let name = input("Session name: ", "")
    if name == ""
        echo "Aborted!"
	return
    endif
    TODO_boot_new
  endif
  if system("bridge list ".name) == ""
    echo "No such session: ".name
    return
  endif
  let s:bridge_name = name
  let s:laststatus = &laststatus
  let &laststatus = 2
  echo "Connected to " . s:bridge_name
endfun

fun! Bridge_disconnect(m)
  if s:bridge_name == ""
    echo "Not connected!"
  else
    let &laststatus = s:laststatus
    let m = "Disconnected from ".s:bridge_name
    if a:m != ""
      let m .= ": ".a:m
    endif
    echo m."!"
    let s:bridge_name = ""
  endif
endfun

function! Bridge_paste( data )
  if a:data == ''
    echo "Nothing to send!"
  else
    let l:data = a:data
    if exists("g:bridge_prologue") | let l:data = g:bridge_prologue . l:data | endif
    if exists("g:bridge_epilogue") | let l:data = l:data . g:bridge_epilogue | endif
    call system("bridge paste " . s:bridge_name, l:data . "\<cr>")
  endif
endfunction

nmap <C-F12> :call Bridge_display()<cr>
nmap [24^ <C-F12>
nmap <F12> :call Bridge_connect()<cr>
nmap <S-F12> :call Bridge_disconnect("")<cr>
nmap [24$ <S-F12>

nmap <leader>el :call Bridge_paste(getline("."))<cr>
nmap <leader>ec m'ya(:call Bridge_paste(getreg('"'))<cr>`'
nmap <leader>et m'(y%:call Bridge_paste(getreg('"'))<cr>`'

nmap <leader>ee :call Bridge_paste(input("paste: ", ""))<cr>

" sugar
nmap <Return> <leader>ec

"" visual shell
vmap <return> m'y:call Bridge_paste(getreg('"'))<cr>v`'
vmap <leader>ee :call Bridge_paste(input("paste: ", ""))<cr>
vmap <leader>et <return>