summaryrefslogtreecommitdiffstats
path: root/bridge
diff options
context:
space:
mode:
authortv <tv@iiso>2011-09-27 00:12:32 +0200
committertv <tv@iiso>2011-09-27 00:12:32 +0200
commitf541b6139ca8ecbc64c736179604280e3006bede (patch)
tree58ac7c926a00b0573a0173dd1de91506bcab098a /bridge
parentf56a4735ade90afcc719d9b87e941a665768db70 (diff)
//bridge: initial commit
Diffstat (limited to 'bridge')
-rwxr-xr-xbridge/bin/bridge5
-rw-r--r--bridge/etc/bash_completion.d/bridge18
-rwxr-xr-xbridge/lib/bridge/bin/attach3
-rwxr-xr-xbridge/lib/bridge/bin/create6
-rwxr-xr-xbridge/lib/bridge/bin/destroy3
-rwxr-xr-xbridge/lib/bridge/bin/list3
-rwxr-xr-xbridge/lib/bridge/bin/paste17
-rw-r--r--bridge/share/vim/plugin/bridge.vim113
8 files changed, 168 insertions, 0 deletions
diff --git a/bridge/bin/bridge b/bridge/bin/bridge
new file mode 100755
index 00000000..6ae4ab11
--- /dev/null
+++ b/bridge/bin/bridge
@@ -0,0 +1,5 @@
+#! /bin/sh
+set -euf
+command="$1"; shift
+bindir="$(dirname $(readlink -f "$0"))/../lib/bridge/bin"
+exec "$bindir/$command" "$@"
diff --git a/bridge/etc/bash_completion.d/bridge b/bridge/etc/bash_completion.d/bridge
new file mode 100644
index 00000000..86d8a4e2
--- /dev/null
+++ b/bridge/etc/bash_completion.d/bridge
@@ -0,0 +1,18 @@
+#! /bin/bash
+function comp_bridge() {
+ local cword="${COMP_WORDS[$COMP_CWORD]}"
+ local bindir="$(dirname $(readlink -f "$BASH_SOURCE"))/../../lib/bridge/bin"
+ case $COMP_CWORD in
+ (1)
+ COMPREPLY=( $(cd "$bindir" && ls | grep "^$cword.*") )
+ ;;
+ (2)
+ case "${COMP_WORDS[1]}" in
+ (attach|destroy|paste)
+ COMPREPLY=( $(bridge list 2>/dev/null | grep "^$cword.*") )
+ ;;
+ esac
+ ;;
+ esac
+}
+complete -F comp_bridge bridge
diff --git a/bridge/lib/bridge/bin/attach b/bridge/lib/bridge/bin/attach
new file mode 100755
index 00000000..2edefbe3
--- /dev/null
+++ b/bridge/lib/bridge/bin/attach
@@ -0,0 +1,3 @@
+#! /bin/sh
+set -euf
+exec tmux -L bridge attach-session -t "$1"
diff --git a/bridge/lib/bridge/bin/create b/bridge/lib/bridge/bin/create
new file mode 100755
index 00000000..31b2f3d8
--- /dev/null
+++ b/bridge/lib/bridge/bin/create
@@ -0,0 +1,6 @@
+#! /bin/sh
+set -euf
+target="$1"; shift
+tmux -L bridge new-session -d -s "$target" "$@"
+tmux -L bridge set-buffer READY.
+exec "$(dirname $0)/attach" "$target"
diff --git a/bridge/lib/bridge/bin/destroy b/bridge/lib/bridge/bin/destroy
new file mode 100755
index 00000000..f625d138
--- /dev/null
+++ b/bridge/lib/bridge/bin/destroy
@@ -0,0 +1,3 @@
+#! /bin/sh
+set -euf
+tmux -L bridge kill-session -t "$1"
diff --git a/bridge/lib/bridge/bin/list b/bridge/lib/bridge/bin/list
new file mode 100755
index 00000000..8b164516
--- /dev/null
+++ b/bridge/lib/bridge/bin/list
@@ -0,0 +1,3 @@
+#! /bin/sh
+set -euf
+exec tmux -L bridge list-sessions | cut -d: -f1
diff --git a/bridge/lib/bridge/bin/paste b/bridge/lib/bridge/bin/paste
new file mode 100755
index 00000000..d5a768ad
--- /dev/null
+++ b/bridge/lib/bridge/bin/paste
@@ -0,0 +1,17 @@
+#! /bin/sh
+set -euf
+target="$1"; shift
+if test $# -gt 0; then
+ tmux -L bridge set-buffer -b 0 "$*"
+else
+ if test -n "${VIMRUNTIME-}" || tty >/dev/null; then
+ temp=`mktemp`
+ trap "rm -f $temp" EXIT INT TERM
+ cat>$temp
+ else
+ temp=-
+ fi
+ tmux -L bridge load-buffer -b 0 $temp
+fi
+tmux -L bridge paste-buffer -b 0 -t "$target"
+tmux -L bridge set-buffer -b 0 READY.
diff --git a/bridge/share/vim/plugin/bridge.vim b/bridge/share/vim/plugin/bridge.vim
new file mode 100644
index 00000000..91f072d1
--- /dev/null
+++ b/bridge/share/vim/plugin/bridge.vim
@@ -0,0 +1,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>
+
+