christoomey / vim-tmux-runner

Vim and tmux, sittin' in a tree...
MIT License
291 stars 37 forks source link

Make AttachToPane command smarter #20

Closed christoomey closed 9 years ago

christoomey commented 10 years ago

Always discount the current pane. With the remaining panes:

system('tmux display-message -t 1 -p "#{pane_current_command}"')
system("tmux capture-pane -t 1 -p | grep -v '^$' | tail -1") " gets the last line of output
christoomey commented 9 years ago

Investigated using the following for fancy tab complete input, but decided index based selection was most straighforward:

diff --git a/plugin/vim-tmux-runner.vim b/plugin/vim-tmux-runner.vim
index 5a801ad..faaca88 100644
--- a/plugin/vim-tmux-runner.vim
+++ b/plugin/vim-tmux-runner.vim
@@ -134,7 +134,21 @@ function! s:ZoomRunnerPane()
 endfunction

 function! s:Strip(string)
-    return substitute(a:string, '^\s*\(.\{-}\)\s*$', '\1', '')
+    return substitute(a:string, '^\s*\(.\{-}\)\s*\n\?$', '\1', '')
+endfunction
+
+function! PaneList(A, P, L)
+  let panes = []
+  for i in [1, 2, 3]
+    call add(panes, s:PaneSummary(i))
+  endfor
+  return panes
+endfunction
+
+function! s:PaneSummary(index)
+  let command = s:Strip(system('tmux display-message -t '. a:index . ' -p "#{pane_current_command}"'))
+  let last_line = s:Strip(s:Strip(system("tmux capture-pane -t ". a:index . " -p | grep -v '^$' | tail -1"))[0:30])
+  return "[" . a:index . " " . command . "]: " . last_line
 endfunction

 function! s:SendTmuxCommand(command)