Skip to content

Commit 3693ec6

Browse files
authored
Merge pull request #180 from m42e/preserve-choosesession
Allow setting of VimuxRunner name to reuse session
2 parents 0f5fd2c + af602e3 commit 3693ec6

File tree

2 files changed

+54
-10
lines changed

2 files changed

+54
-10
lines changed

doc/vimux.txt

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ You can configure Vimux like this:
291291

292292
------------------------------------------------------------------------------
293293
*VimuxConfiguration_height*
294-
2.1 g:VimuxHeight~
294+
4.1 g:VimuxHeight~
295295

296296
The percent of the screen the split pane Vimux will spawn should take up.
297297

@@ -301,7 +301,7 @@ Default: "20"
301301

302302
------------------------------------------------------------------------------
303303
*VimuxConfiguration_orientation*
304-
2.2 g:VimuxOrientation~
304+
4.2 g:VimuxOrientation~
305305

306306
The default orientation of the split tmux pane. This tells tmux to make the
307307
pane either vertically or horizontally, which is backward from how Vim handles
@@ -317,7 +317,7 @@ Default: "v"
317317

318318
------------------------------------------------------------------------------
319319
*VimuxConfiguration_use_nearest*
320-
2.3 g:VimuxUseNearest
320+
4.3 g:VimuxUseNearest
321321

322322
Use existing pane or window (not used by vim) if found instead of running
323323
split-window.
@@ -328,7 +328,7 @@ Default: 1
328328

329329
------------------------------------------------------------------------------
330330
*VimuxConfiguration_reset_sequence*
331-
2.4 g:VimuxResetSequence~
331+
4.4 g:VimuxResetSequence~
332332

333333
The keys sent to the runner pane before running a command. By default it sends
334334
`q` to make sure the pane is not in scroll-mode and `C-u` to clear the line.
@@ -339,7 +339,7 @@ Default: "q C-u"
339339

340340
------------------------------------------------------------------------------
341341
*VimuxPromptString*
342-
2.5 g:VimuxPromptString~
342+
4.5 g:VimuxPromptString~
343343

344344
The string presented in the vim command line when Vimux is invoked. Be sure
345345
to put a space at the end of the string to allow for distinction between
@@ -351,7 +351,7 @@ Default: "Command? "
351351

352352
------------------------------------------------------------------------------
353353
*VimuxRunnerType*
354-
2.6 g:VimuxRunnerType~
354+
4.6 g:VimuxRunnerType~
355355

356356
The type of view object Vimux should use for the runner. For reference, a
357357
tmux session is a group of windows, and a window is a layout of panes.
@@ -364,9 +364,21 @@ Options:
364364

365365
Default: "pane"
366366

367+
------------------------------------------------------------------------------
368+
*VimuxRunnerName*
369+
4.7 g:VimuxRunnerName
370+
371+
Setting the name for the runner. Works for panes and windows. This makes the
372+
VimuxRunner reusable between sessions. Caveat is, all your instances (in the
373+
same session/window) use the same window.
374+
375+
let g:VimuxRunnerName = "vimuxout"
376+
377+
Default: ""
378+
367379
------------------------------------------------------------------------------
368380
*VimuxTmuxCommand*
369-
2.7 g:VimuxTmuxCommand~
381+
4.8 g:VimuxTmuxCommand~
370382

371383
The command that Vimux runs when it calls out to tmux. It may be useful to
372384
redefine this if you're using something like tmate.
@@ -376,8 +388,8 @@ redefine this if you're using something like tmate.
376388
Default: "tmux"
377389

378390
------------------------------------------------------------------------------
379-
*VimuxOpenExtraArgs*
380-
2.8 g:VimuxOpenExtraArgs~
391+
*VimuxOpenExtraArgs*
392+
4.9 g:VimuxOpenExtraArgs~
381393

382394
Allows addtional arguments to be passed to the tmux command that opens the
383395
runner. Make sure that the arguments specified are valid depending on whether

plugin/vimux.vim

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ function! VimuxOpenRunner()
9999
endif
100100

101101
let g:VimuxRunnerIndex = _VimuxTmuxIndex()
102+
call _VimuxSetRunnerName()
102103
call _VimuxTmux("last-"._VimuxRunnerType())
103104
endif
104105
endfunction
@@ -172,6 +173,9 @@ function! VimuxPromptCommand(...)
172173
endfunction
173174

174175
function! _VimuxTmux(arguments)
176+
if _VimuxOption("g:VimuxDebug", 0) != 0
177+
echom _VimuxTmuxCmd()." ".a:arguments
178+
endif
175179
return system(_VimuxTmuxCmd()." ".a:arguments)
176180
endfunction
177181

@@ -197,7 +201,8 @@ endfunction
197201

198202
function! _VimuxNearestIndex()
199203
let t = _VimuxRunnerType()
200-
let views = split(_VimuxTmux("list-".t."s -F '#{".t."_active}:#{".t."_id}'"), "\n")
204+
let filter = _VimuxGetTargetFilter()
205+
let views = split(_VimuxTmux("list-".t."s -F '#{".t."_active}:#{".t."_id}'".filter), "\n")
201206

202207
for view in views
203208
if match(view, "1:") == -1
@@ -208,6 +213,33 @@ function! _VimuxNearestIndex()
208213
return -1
209214
endfunction
210215

216+
function! _VimuxGetTargetFilter()
217+
let targetName = _VimuxOption("g:VimuxRunnerName", "")
218+
if targetName == ""
219+
return ""
220+
endif
221+
let t = _VimuxRunnerType()
222+
if t == "window"
223+
return " -f '#{==:#{window_name},".targetName."}'"
224+
elseif t == "pane"
225+
return " -f '#{==:#{pane_title},".targetName."}'"
226+
endif
227+
endfunction
228+
229+
function! _VimuxSetRunnerName()
230+
let targetName = _VimuxOption("g:VimuxRunnerName", "")
231+
if targetName == ""
232+
return
233+
endif
234+
let t = _VimuxRunnerType()
235+
if t == "window"
236+
call _VimuxTmux("rename-window ".targetName)
237+
elseif t == "pane"
238+
call _VimuxTmux("select-pane -T ".targetName)
239+
endif
240+
endfunction
241+
242+
211243
function! _VimuxRunnerType()
212244
return _VimuxOption("g:VimuxRunnerType", "pane")
213245
endfunction

0 commit comments

Comments
 (0)