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

Added possibility to choose a different session #138

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 13 additions & 1 deletion doc/vimux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,21 @@ Options:

Default: "pane"

------------------------------------------------------------------------------
*VimuxTargetSession*
2.7 g:VimuxTargetSession

The session the tmux window should belong to. Works only with VimuxRunnerType
"window". If the session is available the current active window will be used,
else the session will be created.

let g:VimuxRunnerType = "VimuxOut"

Default: ""

------------------------------------------------------------------------------
*VimuxTmuxCommand*
2.7 g:VimuxTmuxCommand~
2.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 Down
70 changes: 59 additions & 11 deletions plugin/vimux.vim
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,49 @@ function! VimuxSendKeys(keys)
endfunction

function! VimuxOpenRunner()
let activeSession = _VimuxGetTargetSession()
let nearestIndex = _VimuxNearestIndex()

if _VimuxOption("g:VimuxUseNearest", 1) == 1 && nearestIndex != -1
let g:VimuxRunnerIndex = nearestIndex
if _VimuxOption("g:VimuxUseNearest", 1) == 1 && nearestIndex != -1 && activeSession != -1
let g:VimuxRunnerIndex = activeSession.':'.nearestIndex
else
if _VimuxRunnerType() == "pane"
let height = _VimuxOption("g:VimuxHeight", 20)
let orientation = _VimuxOption("g:VimuxOrientation", "v")
call _VimuxTmux("split-window -p ".height." -".orientation)
elseif _VimuxRunnerType() == "window"
call _VimuxTmux("new-window")
if activeSession == -1
let activeSession = _VimuxOption("g:VimuxTargetSession", '')
call _VimuxTmuxSpecial("new-session -d -n \"vimux\" -s \"".activeSession."\"")
else
call _VimuxTmux("new-window -t ".activeSession)
endif
endif

let g:VimuxRunnerIndex = _VimuxTmuxIndex()
let g:VimuxRunnerIndex = activeSession.':'._VimuxTmuxIndex()
call _VimuxTmux("last-"._VimuxRunnerType())
endif
endfunction


function! _VimuxGetTargetSession()
let targetSession = ''
if _VimuxOption("g:VimuxTargetSession", '') != ''
let targetSession = g:VimuxTargetSession
let sessions = split(_VimuxTmux("list-sessions"), "\n")

for session in sessions
if match(session, targetSession) != -1
return targetSession
endif
endfor
return -1
else
let targetSession = substitute(_VimuxTmux("display -p '#S'"), '\n$', '', '')
endif
return targetSession
endfunction

function! VimuxCloseRunner()
if exists("g:VimuxRunnerIndex")
call _VimuxTmux("kill-"._VimuxRunnerType()." -t ".g:VimuxRunnerIndex)
Expand Down Expand Up @@ -147,9 +172,20 @@ endfunction

function! _VimuxTmux(arguments)
let l:command = _VimuxOption("g:VimuxTmuxCommand", "tmux")
if _VimuxOption("g:VimuxDebug", 0) != 0
echo l:command." ".a:arguments
endif
return system(l:command." ".a:arguments)
endfunction

function! _VimuxTmuxSpecial(arguments)
let l:command = _VimuxOption("g:VimuxTmuxCommand", "tmux")
if _VimuxOption("g:VimuxDebug", 0) != 0
echo "TMUX= ".l:command." ".a:arguments
endif
return system("TMUX= ".l:command." ".a:arguments)
endfunction

function! _VimuxTmuxSession()
return _VimuxTmuxProperty("#S")
endfunction
Expand All @@ -171,13 +207,25 @@ function! _VimuxTmuxWindowIndex()
endfunction

function! _VimuxNearestIndex()
let views = split(_VimuxTmux("list-"._VimuxRunnerType()."s"), "\n")

for view in views
if match(view, "(active)") == -1
return split(view, ":")[0]
endif
endfor
let targetSession = ''
if _VimuxOption("g:VimuxTargetSession", '') != ''
let targetSession = ' -t '.g:VimuxTargetSession
endif
let views = split(_VimuxTmux("list-"._VimuxRunnerType()."s".targetSession ), "\n")

if _VimuxOption("g:VimuxTargetSession", '') != ''
for view in views
if match(view, "(active)") != -1
return split(view, ":")[0]
endif
endfor
else
for view in views
if match(view, "(active)") == -1
return split(view, ":")[0]
endif
endfor
endif

return -1
endfunction
Expand Down