Skip to content

Commit 1e30ed8

Browse files
committed
Merge pull request #83 from ersatzryan/master
Ability to change runner type
2 parents 6a7fccc + 7212ae4 commit 1e30ed8

File tree

1 file changed

+45
-28
lines changed

1 file changed

+45
-28
lines changed

plugin/vimux.vim

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ command VimuxPromptCommand :call VimuxPromptCommand()
1414
command VimuxClearRunnerHistory :call VimuxClearRunnerHistory()
1515

1616
function! VimuxRunLastCommand()
17-
if exists("g:VimuxRunnerPaneIndex")
17+
if exists("g:VimuxRunnerIndex")
1818
call VimuxRunCommand(g:VimuxLastCommand)
1919
else
2020
echo "No last vimux command."
2121
endif
2222
endfunction
2323

2424
function! VimuxRunCommand(command, ...)
25-
if !exists("g:VimuxRunnerPaneIndex") || _VimuxHasPane(g:VimuxRunnerPaneIndex) == -1
26-
call VimuxOpenPane()
25+
if !exists("g:VimuxRunnerIndex") || _VimuxHasRunner(g:VimuxRunnerIndex) == -1
26+
call VimuxOpenRunner()
2727
endif
2828

2929
let l:autoreturn = 1
@@ -47,31 +47,36 @@ function! VimuxSendText(text)
4747
endfunction
4848

4949
function! VimuxSendKeys(keys)
50-
if exists("g:VimuxRunnerPaneIndex")
51-
call system("tmux send-keys -t ".g:VimuxRunnerPaneIndex." ".a:keys)
50+
if exists("g:VimuxRunnerIndex")
51+
call system("tmux send-keys -t ".g:VimuxRunnerIndex." ".a:keys)
5252
else
53-
echo "No vimux runner pane. Create one with VimuxOpenPane"
53+
echo "No vimux runner pane/window. Create one with VimuxOpenRunner"
5454
endif
5555
endfunction
5656

57-
function! VimuxOpenPane()
58-
let height = _VimuxOption("g:VimuxHeight", 20)
59-
let orientation = _VimuxOption("g:VimuxOrientation", "v")
60-
let nearestIndex = _VimuxNearestPaneIndex()
57+
function! VimuxOpenRunner()
58+
let nearestIndex = _VimuxNearestIndex()
6159

62-
if _VimuxOption("g:VimuxUseNearestPane", 1) == 1 && nearestIndex != -1
63-
let g:VimuxRunnerPaneIndex = nearestIndex
60+
if _VimuxOption("g:VimuxUseNearest", 1) == 1 && nearestIndex != -1
61+
let g:VimuxRunnerIndex = nearestIndex
6462
else
65-
call system("tmux split-window -p ".height." -".orientation)
66-
let g:VimuxRunnerPaneIndex = _VimuxTmuxPaneIndex()
67-
call system("tmux last-pane")
63+
if _VimuxRunnerType() == "pane"
64+
let height = _VimuxOption("g:VimuxHeight", 20)
65+
let orientation = _VimuxOption("g:VimuxOrientation", "v")
66+
call system("tmux split-window -p ".height." -".orientation)
67+
elseif _VimuxRunnerType() == "window"
68+
call system("tmux new-window")
69+
endif
70+
71+
let g:VimuxRunnerIndex = _VimuxTmuxIndex()
72+
call system("tmux last-"._VimuxRunnerType())
6873
endif
6974
endfunction
7075

7176
function! VimuxCloseRunner()
72-
if exists("g:VimuxRunnerPaneIndex")
73-
call system("tmux kill-pane -t ".g:VimuxRunnerPaneIndex)
74-
unlet g:VimuxRunnerPaneIndex
77+
if exists("g:VimuxRunnerIndex")
78+
call system("tmux kill-"._VimuxRunnerType()." -t ".g:VimuxRunnerIndex)
79+
unlet g:VimuxRunnerIndex
7580
endif
7681
endfunction
7782

@@ -83,19 +88,19 @@ function! VimuxZoomRunner()
8388
endfunction
8489

8590
function! VimuxInspectRunner()
86-
call system("tmux select-pane -t ".g:VimuxRunnerPaneIndex)
91+
call system("tmux select-"._VimuxRunnerType()." -t ".g:VimuxRunnerIndex)
8792
call system("tmux copy-mode")
8893
endfunction
8994

9095
function! VimuxScrollUpInspect()
9196
call VimuxInspectRunner()
92-
call system("tmux last-pane")
97+
call system("tmux last-"._VimuxRunnerType())
9398
call VimuxSendKeys("C-u")
9499
endfunction
95100

96101
function! VimuxScrollDownInspect()
97102
call VimuxInspectRunner()
98-
call system("tmux last-pane")
103+
call system("tmux last-"._VimuxRunnerType())
99104
call VimuxSendKeys("C-d")
100105
endfunction
101106

@@ -104,8 +109,8 @@ function! VimuxInterruptRunner()
104109
endfunction
105110

106111
function! VimuxClearRunnerHistory()
107-
if exists("g:VimuxRunnerPaneIndex")
108-
call system("tmux clear-history -t ".g:VimuxRunnerPaneIndex)
112+
if exists("g:VimuxRunnerIndex")
113+
call system("tmux clear-history -t ".g:VimuxRunnerIndex)
109114
endif
110115
endfunction
111116

@@ -118,16 +123,24 @@ function! _VimuxTmuxSession()
118123
return _VimuxTmuxProperty("S")
119124
endfunction
120125

126+
function! _VimuxTmuxIndex()
127+
if _VimuxRunnerType == "pane"
128+
return _VimuxTmuxPaneIndex()
129+
else
130+
return _VimuxTmuxWindowIndex()
131+
end
132+
endfunction
133+
121134
function! _VimuxTmuxPaneIndex()
122-
return _VimuxTmuxProperty("P")
135+
return _VimuxTmuxProperty("P")
123136
endfunction
124137

125138
function! _VimuxTmuxWindowIndex()
126139
return _VimuxTmuxProperty("I")
127140
endfunction
128141

129-
function! _VimuxNearestPaneIndex()
130-
let panes = split(system("tmux list-panes"), "\n")
142+
function! _VimuxNearestIndex()
143+
let panes = split(system("tmux list-"._VimuxRunnerType()."s"), "\n")
131144

132145
for pane in panes
133146
if match(pane, "(active)") == -1
@@ -138,6 +151,10 @@ function! _VimuxNearestPaneIndex()
138151
return -1
139152
endfunction
140153

154+
function! _VimuxRunnerType()
155+
return _VimuxOption("g:VimuxRunnerType", "pane")
156+
endfunction
157+
141158
function! _VimuxOption(option, default)
142159
if exists(a:option)
143160
return eval(a:option)
@@ -150,6 +167,6 @@ function! _VimuxTmuxProperty(property)
150167
return substitute(system("tmux display -p '#".a:property."'"), '\n$', '', '')
151168
endfunction
152169

153-
function! _VimuxHasPane(index)
154-
return match(system("tmux list-panes"), a:index.":")
170+
function! _VimuxHasRunner(index)
171+
return match(system("tmux list-"._VimuxRunnerType()."s"), a:index.":")
155172
endfunction

0 commit comments

Comments
 (0)