Add RotateRunner command
This commit is contained in:
parent
4b7f1c5a42
commit
41bcb5b887
@ -8,24 +8,33 @@
|
|||||||
"
|
"
|
||||||
" Returns:
|
" Returns:
|
||||||
" 1 if the var is set, 0 otherwise
|
" 1 if the var is set, 0 otherwise
|
||||||
function! s:initVariable(var, value)
|
function! s:InitVariable(var, value)
|
||||||
if !exists(a:var)
|
if !exists(a:var)
|
||||||
exec 'let ' . a:var . ' = ' . "'" . substitute(a:value, "'", "''", "g") . "'"
|
let escaped_value = substitute(a:value, "'", "''", "g")
|
||||||
|
exec 'let ' . a:var . ' = ' . "'" . escaped_value . "'"
|
||||||
return 1
|
return 1
|
||||||
endif
|
endif
|
||||||
return 0
|
return 0
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:InitializeVariables()
|
||||||
|
call s:InitVariable("g:VtrPercentage", 20)
|
||||||
|
call s:InitVariable("g:VtrOrientation", "v")
|
||||||
|
endfunction
|
||||||
|
call s:InitializeVariables()
|
||||||
|
|
||||||
function! s:OpenRunnerPane()
|
function! s:OpenRunnerPane()
|
||||||
let s:cached_vim_pane = s:ActiveTmuxPaneNumber()
|
let s:vim_pane = s:ActiveTmuxPaneNumber()
|
||||||
call s:CallTmuxCommand("split-window -p 20 -v")
|
let cmd = join(["split-window -p", g:VtrPercentage, "-".g:VtrOrientation])
|
||||||
let s:cached_runner_pane = s:ActiveTmuxPaneNumber()
|
call s:SendTmuxCommand(cmd)
|
||||||
call s:FocusTmuxPane(s:cached_vim_pane)
|
let s:runner_pane = s:ActiveTmuxPaneNumber()
|
||||||
|
call s:FocusVimPane()
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:KillRunnerPane()
|
function! s:KillRunnerPane()
|
||||||
call s:CallTargetedTmuxCommand("kill-pane", s:cached_runner_pane)
|
let targeted_cmd = s:TargetedTmuxCommand("kill-pane", s:runner_pane)
|
||||||
unlet s:cached_runner_pane
|
call s:SendTmuxCommand(targeted_cmd)
|
||||||
|
unlet s:runner_pane
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:ActiveTmuxPaneNumber()
|
function! s:ActiveTmuxPaneNumber()
|
||||||
@ -37,31 +46,87 @@ function! s:ActiveTmuxPaneNumber()
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:TmuxPanes()
|
function! s:TmuxPanes()
|
||||||
let panes = s:CallTmuxCommand("list-panes")
|
let panes = s:SendTmuxCommand("list-panes")
|
||||||
return split(panes, '\n')
|
return split(panes, '\n')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:FocusTmuxPane(pane_number)
|
function! s:FocusTmuxPane(pane_number)
|
||||||
call s:CallTargetedTmuxCommand("select-pane", a:pane_number)
|
let targeted_cmd = s:TargetedTmuxCommand("select-pane", a:pane_number)
|
||||||
|
call s:SendTmuxCommand(targeted_cmd)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:FocusRunnerPane()
|
function! s:FocusRunnerPane()
|
||||||
call s:FocusTmuxPane(s:cached_runner_pane)
|
call s:FocusTmuxPane(s:runner_pane)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:CallTmuxCommand(command)
|
function! s:SendTmuxCommand(command)
|
||||||
let prexied_command = "tmux " . a:command
|
let prefixed_command = "tmux " . a:command
|
||||||
return system(prexied_command)
|
return system(prefixed_command)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:CallTargetedTmuxCommand(command, target_pane)
|
function! s:TargetedTmuxCommand(command, target_pane)
|
||||||
let targeted_command = a:command . " -t " . a:target_pane
|
return a:command . " -t " . a:target_pane
|
||||||
call s:CallTmuxCommand(targeted_command)
|
endfunction
|
||||||
|
|
||||||
|
function! s:SendEnterSequence()
|
||||||
|
let targeted_cmd = s:TargetedTmuxCommand("send-keys", s:runner_pane)
|
||||||
|
let enter_sequence = targeted_cmd . " Enter"
|
||||||
|
call s:SendTmuxCommand(enter_sequence)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:SendClearSequence()
|
||||||
|
let targeted_cmd = s:TargetedTmuxCommand("send-keys", s:runner_pane)
|
||||||
|
let enter_sequence = targeted_cmd . " clear"
|
||||||
|
call s:SendTmuxCommand(enter_sequence)
|
||||||
|
call s:SendEnterSequence()
|
||||||
|
sleep 50m
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:FocusVimPane()
|
||||||
|
call s:FocusTmuxPane(s:vim_pane)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:TempWindowNumber()
|
||||||
|
return split(s:SendTmuxCommand("list-windows"), '\n')[-1][0]
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:BreakRunnerPaneToTempWindow()
|
||||||
|
let targeted_cmd = s:TargetedTmuxCommand("break-pane", s:runner_pane)
|
||||||
|
let full_command = join([targeted_cmd, "-d"])
|
||||||
|
call s:SendTmuxCommand(full_command)
|
||||||
|
return s:TempWindowNumber()
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:ToggleOrientationVariable()
|
||||||
|
let g:VtrOrientation = (g:VtrOrientation == "v" ? "h" : "v")
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:RotateRunner()
|
||||||
|
let temp_window = s:BreakRunnerPaneToTempWindow()
|
||||||
|
call s:ToggleOrientationVariable()
|
||||||
|
let join_cmd = join(["join-pane", "-s", ":".temp_window.".0", "-p", g:VtrPercentage, "-".g:VtrOrientation])
|
||||||
|
echom join_cmd
|
||||||
|
call s:SendTmuxCommand(join_cmd)
|
||||||
|
call s:FocusVimPane()
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:SendCommandToRunner()
|
||||||
|
echohl String
|
||||||
|
let user_command = shellescape(input("Command to run: "))
|
||||||
|
let targeted_cmd = s:TargetedTmuxCommand("send-keys", s:runner_pane)
|
||||||
|
let full_command = join([targeted_cmd, user_command])
|
||||||
|
call s:SendClearSequence()
|
||||||
|
call s:SendTmuxCommand(full_command)
|
||||||
|
call s:SendEnterSequence()
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
command! VTROpenRunner :call s:OpenRunnerPane()
|
command! VTROpenRunner :call s:OpenRunnerPane()
|
||||||
command! VTRKillRunner :call s:KillRunnerPane()
|
command! VTRKillRunner :call s:KillRunnerPane()
|
||||||
command! VTRFocusRunnerPane :call s:FocusRunnerPane()
|
command! VTRFocusRunnerPane :call s:FocusRunnerPane()
|
||||||
|
command! VTRSendCommandToRunner :call s:SendCommandToRunner()
|
||||||
|
command! VTRRotateRunner :call s:RotateRunner()
|
||||||
|
nmap ,rr :VTRRotateRunner<cr>
|
||||||
|
nmap ,sc :VTRSendCommandToRunner<cr>
|
||||||
nmap ,or :VTROpenRunner<cr>
|
nmap ,or :VTROpenRunner<cr>
|
||||||
nmap ,kr :VTRKillRunner<cr>
|
nmap ,kr :VTRKillRunner<cr>
|
||||||
nmap ,fr :VTRFocusRunnerPane<cr>
|
nmap ,fr :VTRFocusRunnerPane<cr>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user