Skip to content

Commit

Permalink
Use IDs instead of indexes to identify windows and panes (#110)
Browse files Browse the repository at this point in the history
...because indexes can change while IDs are constant and unique.
  • Loading branch information
yunake committed Feb 13, 2021
1 parent fff2f1a commit 1dec716
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions plugin/vimux.vim
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function! VimuxTogglePane()
call _VimuxTmux("join-pane -d -s ".g:VimuxRunnerIndex." -p "._VimuxOption("g:VimuxHeight", 20))
let g:VimuxRunnerType = "pane"
elseif _VimuxRunnerType() == "pane"
let g:VimuxRunnerIndex=substitute(_VimuxTmux("break-pane -d -t ".g:VimuxRunnerIndex." -P -F '#{window_index}'"), "\n", "", "")
let g:VimuxRunnerIndex=substitute(_VimuxTmux("break-pane -d -t ".g:VimuxRunnerIndex." -P -F '#{window_id}'"), "\n", "", "")
let g:VimuxRunnerType = "window"
endif
endif
Expand Down Expand Up @@ -156,26 +156,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(_VimuxTmux("list-"._VimuxRunnerType()."s"), "\n")
let t = _VimuxRunnerType()
let views = split(_VimuxTmux("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 @@ -199,5 +200,6 @@ function! _VimuxTmuxProperty(property)
endfunction

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

0 comments on commit 1dec716

Please sign in to comment.