Skip to content

Commit

Permalink
Add comments and licence.
Browse files Browse the repository at this point in the history
Make some functions local to script as recommanded in ':help write-plugin'
  • Loading branch information
cc0ut committed Feb 1, 2011
1 parent 7d29629 commit b36ec3d
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions tslime.vim
@@ -1,3 +1,15 @@
" Tslime.vim. Send portion of buffer to tmux instance
" Maintainer: C.Coutinho <kikijump [at] gmail [dot] com>
" Licence: DWTFYWTPL

if exists("g:tslime_loaded")
finish
endif

let g:tslime_loaded = 1

" Main function.
" Use it in your script if you want to send text to a tmux session.
function! Send_to_Tmux(text)
if !exists("b:tmux_sessionname") || !exists("b:tmux_windowname")
if exists("g:tmux_sessionname") && exists("g:tmux_windowname")
Expand All @@ -7,7 +19,7 @@ function! Send_to_Tmux(text)
let b:tmux_panenumber = g:tmux_panenumber
end
else
call Tmux_Vars()
call <SID>Tmux_Vars()
end
end

Expand All @@ -21,19 +33,23 @@ function! Send_to_Tmux(text)
call system("tmux paste-buffer -t " . target)
endfunction

" Session completion
function! Tmux_Session_Names(A,L,P)
return system("tmux list-sessions | sed -e 's/:.*$//'")
endfunction

" Window completion
function! Tmux_Window_Names(A,L,P)
return system("tmux list-windows -t" . b:tmux_sessionname . ' | grep -e "^\w:" | sed -e "s/ \[[0-9x]*\]$//"')
endfunction

" Pane completion
function! Tmux_Pane_Numbers(A,L,P)
return system("tmux list-panes -t " . b:tmux_sessionname . ":" . b:tmux_windowname . " | sed -e 's/:.*$//'")
endfunction

function! Tmux_Vars()
" set tslime.vim variables
function! s:Tmux_Vars()
let b:tmux_sessionname = input("session name: ", "", "custom,Tmux_Session_Names")
let b:tmux_windowname = substitute(input("window name: ", "", "custom,Tmux_Window_Names"), ":.*$" , '', 'g')

Expand All @@ -55,4 +71,4 @@ endfunction
vmap <C-c><C-c> "ry :call Send_to_Tmux(@r)<CR>
nmap <C-c><C-c> vip<C-c><C-c>
nmap <C-c>v :call Tmux_Vars()<CR>
nmap <C-c>v :call <SID>Tmux_Vars()<CR>

0 comments on commit b36ec3d

Please sign in to comment.