@ -3,7 +3,7 @@ if exists('g:loaded_vimux') || &compatible
endif
let g :loaded_vimux = 1
function ! s: VimuxOption( option , default )
function ! VimuxOption( option , default )
if exists ( a :option )
return eval ( a :option )
else
@ -11,12 +11,12 @@ function! s:VimuxOption(option, default)
endif
endfunction
function ! s :VimuxT muxCmd( )
return s: VimuxOption( 'g:VimuxTmuxCommand' , 'tmux' )
function ! s :t muxCmd( )
return VimuxOption( 'g:VimuxTmuxCommand' , 'tmux' )
endfunction
if ! executable ( s :VimuxT muxCmd( ) )
echohl ErrorMsg | echomsg 'Failed to find executable ' .s :VimuxT muxCmd( ) | echohl None
if ! executable ( s :t muxCmd( ) )
echohl ErrorMsg | echomsg 'Failed to find executable ' .s :t muxCmd( ) | echohl None
finish
endif
@ -51,21 +51,17 @@ function! VimuxRunLastCommand()
endfunction
function ! VimuxRunCommand ( command , ...)
if ! exists ( 'g:VimuxRunnerIndex' ) | | s :VimuxH asRunner( g :VimuxRunnerIndex ) = = # -1
if ! exists ( 'g:VimuxRunnerIndex' ) | | s :h asRunner( g :VimuxRunnerIndex ) = = # -1
call VimuxOpenRunner ( )
endif
let l :autoreturn = 1
if exists ( 'a:1' )
let l :autoreturn = a :1
endif
let resetSequence = s :VimuxOption ( 'g:VimuxResetSequence' , 'q C-u' )
let resetSequence = VimuxOption ( 'g:VimuxResetSequence' , 'q C-u' )
let g :VimuxLastCommand = a :command
call VimuxSendKeys ( resetSequence )
call VimuxSendText ( a :command )
if l :autoreturn = = # 1
call VimuxSendKeys ( 'Enter' )
endif
@ -77,47 +73,45 @@ endfunction
function ! VimuxSendKeys ( keys )
if exists ( 'g:VimuxRunnerIndex' )
call s: VimuxTmux( 'send-keys -t ' .g :VimuxRunnerIndex .' ' .a :keys )
call VimuxTmux( 'send-keys -t ' .g :VimuxRunnerIndex .' ' .a :keys )
else
echo 'No vimux runner pane/window. Create one with VimuxOpenRunner'
endif
endfunction
function ! VimuxOpenRunner ( )
let nearestIndex = s :VimuxNearestIndex ( )
if s :VimuxOption ( 'g:VimuxUseNearest' , 1 ) = = # 1 && nearestIndex ! = -1
let nearestIndex = s :nearestIndex ( )
if VimuxOption ( 'g:VimuxUseNearest' , 1 ) = = # 1 && nearestIndex ! = -1
let g :VimuxRunnerIndex = nearestIndex
else
let extraArguments = s: VimuxOption( 'g:VimuxOpenExtraArgs' , '' )
if s :VimuxR unnerType( ) = = # 'pane'
let height = s: VimuxOption( 'g:VimuxHeight' , 20 )
let orientation = s: VimuxOption( 'g:VimuxOrientation' , 'v' )
call s: VimuxTmux( 'split-window -p ' .height .' -' .orientation .' ' .extraArguments )
elseif s :VimuxR unnerType( ) = = # 'window'
call s: VimuxTmux( 'new-window ' .extraArguments )
let extraArguments = VimuxOption( 'g:VimuxOpenExtraArgs' , '' )
if s :r unnerType( ) = = # 'pane'
let height = VimuxOption( 'g:VimuxHeight' , 20 )
let orientation = VimuxOption( 'g:VimuxOrientation' , 'v' )
call VimuxTmux( 'split-window -p ' .height .' -' .orientation .' ' .extraArguments )
elseif s :r unnerType( ) = = # 'window'
call VimuxTmux( 'new-window ' .extraArguments )
endif
let g :VimuxRunnerIndex = s :VimuxTmuxIndex ( )
call s :VimuxSetRunnerName ( )
call s :VimuxTmux ( 'last-' .s :VimuxRunnerType ( ) )
let g :VimuxRunnerIndex = s :tmuxIndex ( )
call s :setRunnerName ( )
call VimuxTmux ( 'last-' .s :runnerType ( ) )
endif
endfunction
function ! VimuxCloseRunner ( )
if exists ( 'g:VimuxRunnerIndex' )
call s: VimuxTmux( 'kill-' .s :VimuxR unnerType( ) .' -t ' .g :VimuxRunnerIndex )
call VimuxTmux( 'kill-' .s :r unnerType( ) .' -t ' .g :VimuxRunnerIndex )
unlet g :VimuxRunnerIndex
endif
endfunction
function ! VimuxTogglePane ( )
if exists ( 'g:VimuxRunnerIndex' )
if s :VimuxR unnerType( ) = = # 'window'
call s: VimuxTmux( 'join-pane -d -s ' .g :VimuxRunnerIndex .' -p ' .s :VimuxOption ( 'g:VimuxHeight' , 20 ) )
if s :r unnerType( ) = = # 'window'
call VimuxTmux( 'join-pane -d -s ' .g :VimuxRunnerIndex .' -p ' .VimuxOption ( 'g:VimuxHeight' , 20 ) )
let g :VimuxRunnerType = 'pane'
elseif s :VimuxR unnerType( ) = = # 'pane'
let g :VimuxRunnerIndex = substitute ( s: VimuxTmux( 'break-pane -d -t ' .g :VimuxRunnerIndex ." -P -F '#{window_id}'" ) , '\n' , '' , '' )
elseif s :r unnerType( ) = = # 'pane'
let g :VimuxRunnerIndex = substitute ( VimuxTmux( 'break-pane -d -t ' .g :VimuxRunnerIndex ." -P -F '#{window_id}'" ) , '\n' , '' , '' )
let g :VimuxRunnerType = 'window'
endif
endif
@ -125,28 +119,28 @@ endfunction
function ! VimuxZoomRunner ( )
if exists ( 'g:VimuxRunnerIndex' )
if s :VimuxR unnerType( ) = = # 'pane'
call s: VimuxTmux( 'resize-pane -Z -t ' .g :VimuxRunnerIndex )
elseif s :VimuxR unnerType( ) = = # 'window'
call s: VimuxTmux( 'select-window -t ' .g :VimuxRunnerIndex )
if s :r unnerType( ) = = # 'pane'
call VimuxTmux( 'resize-pane -Z -t ' .g :VimuxRunnerIndex )
elseif s :r unnerType( ) = = # 'window'
call VimuxTmux( 'select-window -t ' .g :VimuxRunnerIndex )
endif
endif
endfunction
function ! VimuxInspectRunner ( )
call s: VimuxTmux( 'select-' .s :VimuxR unnerType( ) .' -t ' .g :VimuxRunnerIndex )
call s: VimuxTmux( 'copy-mode' )
call VimuxTmux( 'select-' .s :r unnerType( ) .' -t ' .g :VimuxRunnerIndex )
call VimuxTmux( 'copy-mode' )
endfunction
function ! VimuxScrollUpInspect ( )
call VimuxInspectRunner ( )
call s: VimuxTmux( 'last-' .s :VimuxR unnerType( ) )
call VimuxTmux( 'last-' .s :r unnerType( ) )
call VimuxSendKeys ( 'C-u' )
endfunction
function ! VimuxScrollDownInspect ( )
call VimuxInspectRunner ( )
call s: VimuxTmux( 'last-' .s :VimuxR unnerType( ) )
call VimuxTmux( 'last-' .s :r unnerType( ) )
call VimuxSendKeys ( 'C-d' )
endfunction
@ -162,63 +156,61 @@ endfunction
function ! VimuxClearRunnerHistory ( )
if exists ( 'g:VimuxRunnerIndex' )
call s: VimuxTmux( 'clear-history -t ' .g :VimuxRunnerIndex )
call VimuxTmux( 'clear-history -t ' .g :VimuxRunnerIndex )
endif
endfunction
function ! VimuxPromptCommand ( ...)
let command = a :0 = = # 1 ? a :1 : ''
let l :command = input ( s: VimuxOption( 'g:VimuxPromptString' , 'Command? ' ) , command , 'shellcmd' )
let l :command = input ( VimuxOption( 'g:VimuxPromptString' , 'Command? ' ) , command , 'shellcmd' )
call VimuxRunCommand ( l :command )
endfunction
function ! s: VimuxTmux( arguments )
if s: VimuxOption( 'g:VimuxDebug' , 0 ) ! = 0
echom s :VimuxT muxCmd( ) .' ' .a :arguments
function ! VimuxTmux( arguments )
if VimuxOption( 'g:VimuxDebug' , 0 ) ! = 0
echom s :t muxCmd( ) .' ' .a :arguments
endif
return system ( s :VimuxT muxCmd( ) .' ' .a :arguments )
return system ( s :t muxCmd( ) .' ' .a :arguments )
endfunction
function ! s :VimuxT muxSession( )
return s :VimuxT muxProperty( '#S' )
function ! s :t muxSession( )
return s :t muxProperty( '#S' )
endfunction
function ! s :VimuxT muxIndex( )
if s :VimuxR unnerType( ) = = # 'pane'
return s :VimuxT muxPaneId( )
function ! s :t muxIndex( )
if s :r unnerType( ) = = # 'pane'
return s :t muxPaneId( )
else
return s :VimuxT muxWindowId( )
return s :t muxWindowId( )
end
endfunction
function ! s :VimuxT muxPaneId( )
return s :VimuxT muxProperty( '#{pane_id}' )
function ! s :t muxPaneId( )
return s :t muxProperty( '#{pane_id}' )
endfunction
function ! s :VimuxT muxWindowId( )
return s :VimuxT muxProperty( '#{window_id}' )
function ! s :t muxWindowId( )
return s :t muxProperty( '#{window_id}' )
endfunction
function ! s :VimuxNearestIndex ( )
let t = s :VimuxRunnerType ( )
let filter = s :VimuxGetTargetFilter ( )
let views = split ( s :VimuxTmux ( 'list-' .t ."s -F '#{" .t .'_active}:#{' .t ."_id}'" .filter ) , '\n' )
function ! s :nearestIndex ( )
let t = s :runnerType ( )
let filter = s :getTargetFilter ( )
let views = split ( VimuxTmux ( 'list-' .t ."s -F '#{" .t .'_active}:#{' .t ."_id}'" .filter ) , '\n' )
for view in views
if match ( view , '1:' ) = = # -1
return split ( view , ':' ) [1 ]
endif
endfor
return -1
endfunction
function ! s :VimuxG etTargetFilter( )
let targetName = s: VimuxOption( 'g:VimuxRunnerName' , '' )
function ! s :g etTargetFilter( )
let targetName = VimuxOption( 'g:VimuxRunnerName' , '' )
if targetName = = # ''
return ''
endif
let t = s :VimuxR unnerType( )
let t = s :r unnerType( )
if t = = # 'window'
return " -f '#{==:#{window_name}," .targetName ."}'"
elseif t = = # 'pane'
@ -226,29 +218,28 @@ function! s:VimuxGetTargetFilter()
endif
endfunction
function ! s :VimuxS etRunnerName( )
let targetName = s: VimuxOption( 'g:VimuxRunnerName' , '' )
function ! s :s etRunnerName( )
let targetName = VimuxOption( 'g:VimuxRunnerName' , '' )
if targetName = = # ''
return
return
endif
let t = s :VimuxR unnerType( )
let t = s :r unnerType( )
if t = = # 'window'
call s: VimuxTmux( 'rename-window ' .targetName )
call VimuxTmux( 'rename-window ' .targetName )
elseif t = = # 'pane'
call s: VimuxTmux( 'select-pane -T ' .targetName )
call VimuxTmux( 'select-pane -T ' .targetName )
endif
endfunction
function ! s :VimuxRunnerType ( )
return s :VimuxOption ( 'g:VimuxRunnerType' , 'pane' )
function ! s :runnerType ( )
return VimuxOption ( 'g:VimuxRunnerType' , 'pane' )
endfunction
function ! s :VimuxT muxProperty( property )
return substitute ( s: VimuxTmux( "display -p '" .a :property ."'" ) , '\n$' , '' , '' )
function ! s :t muxProperty( property )
return substitute ( VimuxTmux( "display -p '" .a :property ."'" ) , '\n$' , '' , '' )
endfunction
function ! s :VimuxH asRunner( index )
let t = s :VimuxR unnerType( )
return match ( s: VimuxTmux( 'list-' .t ."s -F '#{" .t ."_id}'" ) , a :index )
function ! s :h asRunner( index )
let t = s :r unnerType( )
return match ( VimuxTmux( 'list-' .t ."s -F '#{" .t ."_id}'" ) , a :index )
endfunction