Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting of VimuxRunner name to reuse session #180

Merged
merged 1 commit into from
Feb 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions doc/vimux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ You can configure Vimux like this:

------------------------------------------------------------------------------
*VimuxConfiguration_height*
2.1 g:VimuxHeight~
4.1 g:VimuxHeight~

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

Expand All @@ -301,7 +301,7 @@ Default: "20"

------------------------------------------------------------------------------
*VimuxConfiguration_orientation*
2.2 g:VimuxOrientation~
4.2 g:VimuxOrientation~

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

------------------------------------------------------------------------------
*VimuxConfiguration_use_nearest*
2.3 g:VimuxUseNearest
4.3 g:VimuxUseNearest

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

------------------------------------------------------------------------------
*VimuxConfiguration_reset_sequence*
2.4 g:VimuxResetSequence~
4.4 g:VimuxResetSequence~

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

------------------------------------------------------------------------------
*VimuxPromptString*
2.5 g:VimuxPromptString~
4.5 g:VimuxPromptString~

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

------------------------------------------------------------------------------
*VimuxRunnerType*
2.6 g:VimuxRunnerType~
4.6 g:VimuxRunnerType~

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

Default: "pane"

------------------------------------------------------------------------------
*VimuxRunnerName*
4.7 g:VimuxRunnerName

Setting the name for the runner. Works for panes and windows. This makes the
VimuxRunner reusable between sessions. Caveat is, all your instances (in the
same session/window) use the same window.

let g:VimuxRunnerName = "vimuxout"

Default: ""

------------------------------------------------------------------------------
*VimuxTmuxCommand*
2.7 g:VimuxTmuxCommand~
4.8 g:VimuxTmuxCommand~

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

------------------------------------------------------------------------------
*VimuxOpenExtraArgs*
2.8 g:VimuxOpenExtraArgs~
*VimuxOpenExtraArgs*
4.9 g:VimuxOpenExtraArgs~

Allows addtional arguments to be passed to the tmux command that opens the
runner. Make sure that the arguments specified are valid depending on whether
Expand Down
34 changes: 33 additions & 1 deletion plugin/vimux.vim
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ function! VimuxOpenRunner()
endif

let g:VimuxRunnerIndex = _VimuxTmuxIndex()
call _VimuxSetRunnerName()
call _VimuxTmux("last-"._VimuxRunnerType())
endif
endfunction
Expand Down Expand Up @@ -172,6 +173,9 @@ function! VimuxPromptCommand(...)
endfunction

function! _VimuxTmux(arguments)
if _VimuxOption("g:VimuxDebug", 0) != 0
echom _VimuxTmuxCmd()." ".a:arguments
endif
return system(_VimuxTmuxCmd()." ".a:arguments)
endfunction

Expand All @@ -197,7 +201,8 @@ endfunction

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

for view in views
if match(view, "1:") == -1
Expand All @@ -208,6 +213,33 @@ function! _VimuxNearestIndex()
return -1
endfunction

function! _VimuxGetTargetFilter()
let targetName = _VimuxOption("g:VimuxRunnerName", "")
if targetName == ""
return ""
endif
let t = _VimuxRunnerType()
if t == "window"
return " -f '#{==:#{window_name},".targetName."}'"
elseif t == "pane"
return " -f '#{==:#{pane_title},".targetName."}'"
endif
endfunction

function! _VimuxSetRunnerName()
let targetName = _VimuxOption("g:VimuxRunnerName", "")
if targetName == ""
return
endif
let t = _VimuxRunnerType()
if t == "window"
call _VimuxTmux("rename-window ".targetName)
elseif t == "pane"
call _VimuxTmux("select-pane -T ".targetName)
endif
endfunction


function! _VimuxRunnerType()
return _VimuxOption("g:VimuxRunnerType", "pane")
endfunction
Expand Down