Reorganize initialization code
This commit is contained in:
parent
369fba87b5
commit
1c8250b229
@ -4,7 +4,8 @@ A simple, vimscript only, command runner for sending commands from vim to tmux
|
|||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
|
|
||||||
This plugin exposes a command to open a small command runner window
|
This plugin exposes a command to open a small command runner window in a tmux
|
||||||
|
pane, then send commands to it.
|
||||||
|
|
||||||
- Open runner window
|
- Open runner window
|
||||||
- Automatic cd to project root (via git cdup)
|
- Automatic cd to project root (via git cdup)
|
||||||
@ -12,9 +13,13 @@ This plugin exposes a command to open a small command runner window
|
|||||||
- Enter tmux-copy mode in pane
|
- Enter tmux-copy mode in pane
|
||||||
- Maximize the runner pane
|
- Maximize the runner pane
|
||||||
|
|
||||||
|
Full documentation can be found [here][].
|
||||||
|
|
||||||
## Inspiration
|
## Inspiration
|
||||||
|
|
||||||
This plugin is heavily inspired by the functionality in the Vimux plugin. This
|
This plugin is heavily inspired by the functionality in the Vimux plugin. This
|
||||||
plugin aims to implement a similar feature set while not requiring Vim with
|
plugin aims to implement a similar feature set while not requiring Vim with
|
||||||
ruby requirement. In addition a few new commands not found in Vimux have been
|
ruby requirement. In addition a few new commands not found in Vimux have been
|
||||||
added to provide additional control over the tmux runner pane.
|
added to provide additional control over the tmux runner pane.
|
||||||
|
|
||||||
|
[here]: https://github.com/christoomey/vim-tmux-runner/blob/master/doc/vim-tmux-runner.txt
|
||||||
|
@ -1,13 +1,3 @@
|
|||||||
" Function: s:initVariable() function {{{2
|
|
||||||
" This function is used to initialise a given variable to a given value. The
|
|
||||||
" variable is only initialised if it does not exist prior
|
|
||||||
"
|
|
||||||
" Args:
|
|
||||||
" var: the name of the var to be initialised
|
|
||||||
" value: the value to initialise var to
|
|
||||||
"
|
|
||||||
" Returns:
|
|
||||||
" 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)
|
||||||
let escaped_value = substitute(a:value, "'", "''", "g")
|
let escaped_value = substitute(a:value, "'", "''", "g")
|
||||||
@ -22,9 +12,12 @@ function! s:InitializeVariables()
|
|||||||
call s:InitVariable("g:VtrOrientation", "v")
|
call s:InitVariable("g:VtrOrientation", "v")
|
||||||
call s:InitVariable("g:VtrInitialCommand", "")
|
call s:InitVariable("g:VtrInitialCommand", "")
|
||||||
call s:InitVariable("g:VtrClearBeforeSend", 1)
|
call s:InitVariable("g:VtrClearBeforeSend", 1)
|
||||||
|
call s:InitVariable("g:VtrGitCdUpOnOpen", 1)
|
||||||
call s:InitVariable("g:VtrPrompt", "Command to run: ")
|
call s:InitVariable("g:VtrPrompt", "Command to run: ")
|
||||||
|
call s:InitVariable("g:VtrUseVtrMaps", 1)
|
||||||
|
call s:InitVariable("g:VtrClearOnResize", 1)
|
||||||
|
call s:InitVariable("g:VtrClearOnReorient", 1)
|
||||||
endfunction
|
endfunction
|
||||||
call s:InitializeVariables()
|
|
||||||
|
|
||||||
function! s:OpenRunnerPane()
|
function! s:OpenRunnerPane()
|
||||||
let s:vim_pane = s:ActiveTmuxPaneNumber()
|
let s:vim_pane = s:ActiveTmuxPaneNumber()
|
||||||
@ -32,6 +25,9 @@ function! s:OpenRunnerPane()
|
|||||||
call s:SendTmuxCommand(cmd)
|
call s:SendTmuxCommand(cmd)
|
||||||
let s:runner_pane = s:ActiveTmuxPaneNumber()
|
let s:runner_pane = s:ActiveTmuxPaneNumber()
|
||||||
call s:FocusVimPane()
|
call s:FocusVimPane()
|
||||||
|
if g:VtrGitCdUpOnOpen
|
||||||
|
call s:GitCdUp()
|
||||||
|
endif
|
||||||
if g:VtrInitialCommand != ""
|
if g:VtrInitialCommand != ""
|
||||||
call s:SendKeys(g:VtrInitialCommand)
|
call s:SendKeys(g:VtrInitialCommand)
|
||||||
call s:SendClearSequence()
|
call s:SendClearSequence()
|
||||||
@ -66,7 +62,8 @@ function! s:RunnerPaneDimensions()
|
|||||||
let panes = s:TmuxPanes()
|
let panes = s:TmuxPanes()
|
||||||
for pane in panes
|
for pane in panes
|
||||||
if pane =~ '^'.s:runner_pane
|
if pane =~ '^'.s:runner_pane
|
||||||
let pane_info = matchlist(pane, s:runner_pane.': [\(\d\+\)x\(\d\+\)\]')
|
let pattern = s:runner_pane.': [\(\d\+\)x\(\d\+\)\]'
|
||||||
|
let pane_info = matchlist(pane, pattern)
|
||||||
return {'width': pane_info[1], 'height': pane_info[2]}
|
return {'width': pane_info[1], 'height': pane_info[2]}
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
@ -75,7 +72,8 @@ endfunction
|
|||||||
function! s:ResizeRunnerPane()
|
function! s:ResizeRunnerPane()
|
||||||
let new_percent = s:HighlightedPrompt("Runner screen percentage: ")
|
let new_percent = s:HighlightedPrompt("Runner screen percentage: ")
|
||||||
let pane_dimensions = s:RunnerPaneDimensions()
|
let pane_dimensions = s:RunnerPaneDimensions()
|
||||||
let inputs = [pane_dimensions['height'], '*', new_percent, '/', g:VtrPercentage]
|
let inputs = [pane_dimensions['height'], '*', new_percent,
|
||||||
|
\ '/', g:VtrPercentage]
|
||||||
let new_lines = eval(join(inputs)) " Not sure why I need to use eval...?
|
let new_lines = eval(join(inputs)) " Not sure why I need to use eval...?
|
||||||
let lines_delta = abs(pane_dimensions['height'] - new_lines)
|
let lines_delta = abs(pane_dimensions['height'] - new_lines)
|
||||||
let move_down = (eval(join([new_percent, '<', g:VtrPercentage])))
|
let move_down = (eval(join([new_percent, '<', g:VtrPercentage])))
|
||||||
@ -84,11 +82,11 @@ function! s:ResizeRunnerPane()
|
|||||||
let full_command = join([targeted_cmd, direction, lines_delta])
|
let full_command = join([targeted_cmd, direction, lines_delta])
|
||||||
let g:VtrPercentage = new_percent
|
let g:VtrPercentage = new_percent
|
||||||
call s:SendTmuxCommand(full_command)
|
call s:SendTmuxCommand(full_command)
|
||||||
|
if g:VtrClearOnResize
|
||||||
|
call s:SendClearSequence()
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
command! VTRResizePane :call s:ResizeRunnerPane()
|
|
||||||
nmap ,rr :VTRResizePane<cr>
|
|
||||||
|
|
||||||
function! s:FocusRunnerPane()
|
function! s:FocusRunnerPane()
|
||||||
call s:FocusTmuxPane(s:runner_pane)
|
call s:FocusTmuxPane(s:runner_pane)
|
||||||
endfunction
|
endfunction
|
||||||
@ -122,6 +120,14 @@ function! s:SendClearSequence()
|
|||||||
sleep 50m
|
sleep 50m
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:GitCdUp()
|
||||||
|
let git_repo_check = "git rev-parse --git-dir > /dev/null 2>&1"
|
||||||
|
let cdup_cmd = "cd './'$(git rev-parse --show-cdup)"
|
||||||
|
let cmd = shellescape(join([git_repo_check, '&&', cdup_cmd]))
|
||||||
|
call s:SendKeys(cmd)
|
||||||
|
call s:SendClearSequence()
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:FocusVimPane()
|
function! s:FocusVimPane()
|
||||||
call s:FocusTmuxPane(s:vim_pane)
|
call s:FocusTmuxPane(s:vim_pane)
|
||||||
endfunction
|
endfunction
|
||||||
@ -147,7 +153,9 @@ function! s:ReorientRunner()
|
|||||||
let join_cmd = join(["join-pane", "-s", ":".temp_window.".0",
|
let join_cmd = join(["join-pane", "-s", ":".temp_window.".0",
|
||||||
\ "-p", g:VtrPercentage, "-".g:VtrOrientation])
|
\ "-p", g:VtrPercentage, "-".g:VtrOrientation])
|
||||||
call s:SendTmuxCommand(join_cmd)
|
call s:SendTmuxCommand(join_cmd)
|
||||||
call s:SendClearSequence()
|
if g:VtrClearOnReorient
|
||||||
|
call s:SendClearSequence()
|
||||||
|
endif
|
||||||
call s:FocusVimPane()
|
call s:FocusVimPane()
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@ -164,13 +172,26 @@ function! s:SendCommandToRunner()
|
|||||||
call s:SendKeys(user_command)
|
call s:SendKeys(user_command)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
command! VTROpenRunner :call s:OpenRunnerPane()
|
function! s:DefineCommands()
|
||||||
command! VTRKillRunner :call s:KillRunnerPane()
|
command! VTROpenRunner :call s:OpenRunnerPane()
|
||||||
command! VTRFocusRunnerPane :call s:FocusRunnerPane()
|
command! VTRKillRunner :call s:KillRunnerPane()
|
||||||
command! VTRSendCommandToRunner :call s:SendCommandToRunner()
|
command! VTRFocusRunnerPane :call s:FocusRunnerPane()
|
||||||
command! VTRReorientRunner :call s:ReorientRunner()
|
command! VTRSendCommandToRunner :call s:SendCommandToRunner()
|
||||||
nmap ,ror :VTRReorientRunner<cr>
|
command! VTRReorientRunner :call s:ReorientRunner()
|
||||||
nmap ,sc :VTRSendCommandToRunner<cr>
|
command! VTRResizePane :call s:ResizeRunnerPane()
|
||||||
nmap ,or :VTROpenRunner<cr>
|
endfunction
|
||||||
nmap ,kr :VTRKillRunner<cr>
|
|
||||||
nmap ,fr :VTRFocusRunnerPane<cr>
|
function! s:DefineKeymaps()
|
||||||
|
if g:VtrUseVtrMaps
|
||||||
|
nmap ,rr :VTRResizePane<cr>
|
||||||
|
nmap ,ror :VTRReorientRunner<cr>
|
||||||
|
nmap ,sc :VTRSendCommandToRunner<cr>
|
||||||
|
nmap ,or :VTROpenRunner<cr>
|
||||||
|
nmap ,kr :VTRKillRunner<cr>
|
||||||
|
nmap ,fr :VTRFocusRunnerPane<cr>
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
call s:InitializeVariables()
|
||||||
|
call s:DefineCommands()
|
||||||
|
call s:DefineKeymaps()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user