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

Use IDs instead of indexes to identify the Runner #110

Merged
merged 2 commits into from
Feb 13, 2021
Merged
Changes from 1 commit
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
24 changes: 13 additions & 11 deletions plugin/vimux.vim
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function! VimuxTogglePane()
call system("tmux join-pane -d -s ".g:VimuxRunnerIndex." -p "._VimuxOption("g:VimuxHeight", 20))
let g:VimuxRunnerType = "pane"
elseif _VimuxRunnerType() == "pane"
let g:VimuxRunnerIndex=substitute(system("tmux break-pane -d -t ".g:VimuxRunnerIndex." -P -F '#{window_index}'"), "\n", "", "")
let g:VimuxRunnerIndex=substitute(system("tmux break-pane -d -t ".g:VimuxRunnerIndex." -P -F '#{window_id}'"), "\n", "", "")
let g:VimuxRunnerType = "window"
endif
endif
Expand Down Expand Up @@ -142,26 +142,27 @@ endfunction

function! _VimuxTmuxIndex()
if _VimuxRunnerType() == "pane"
return _VimuxTmuxPaneIndex()
return _VimuxTmuxPaneId()
else
return _VimuxTmuxWindowIndex()
return _VimuxTmuxWindowId()
end
endfunction

function! _VimuxTmuxPaneIndex()
return _VimuxTmuxProperty("#I.#P")
function! _VimuxTmuxPaneId()
return _VimuxTmuxProperty("#{pane_id}")
endfunction

function! _VimuxTmuxWindowIndex()
return _VimuxTmuxProperty("#I")
function! _VimuxTmuxWindowId()
return _VimuxTmuxProperty("#{window_id}")
endfunction

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

for view in views
if match(view, "(active)") == -1
return split(view, ":")[0]
if match(view, "1:") == -1
return split(view, ":")[1]
endif
endfor

Expand All @@ -185,5 +186,6 @@ function! _VimuxTmuxProperty(property)
endfunction

function! _VimuxHasRunner(index)
return match(system("tmux list-"._VimuxRunnerType()."s -a"), a:index.":")
let t = _VimuxRunnerType()
return match(system("tmux list-".t."s -F '#{".t."_id}'"), a:index)
endfunction