Skip to content

Respect value of g:VimuxRunnerIndex #235

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

3ximus
Copy link

@3ximus 3ximus commented Nov 24, 2024

Hello!
This PR aims to solve an issue I have that is to select a specific pane to be the runner (any pane across all sessions). I found that the behavior to interact with the runner was slightly inconsistent and didn't quite allow for that.

The best solution I found was to select the runner through the g:VimuxRunnerIndex, but without these fixes I wasn't able to use it reliably since VimuxOpenRunner would try to get a new runner every time and VimuxRunCommand wouldn't recognize the pane unless it's on the current window.

I tested most use cases and it seems to respect the old behavior. Let me know if you agree with this.

PS: This is how I'm using it btw using fzf to pick a pane from the current session (could be adapted to do the same for all sessions)

function s:VimuxSetPane(line)
  let l:pane_path = substitute(a:line, '[* ]\+\(\d\+\.\d\+\) .*','\1', '')
  let g:VimuxRunnerIndex = substitute(VimuxTmux('display -t '.l:pane_path.' -p "#{pane_id}"'), '\n$', '', '')
endfunction

function s:VimuxPickPaneFzf()
  let opts = {
        \ 'source': 'tmux list-panes -s -F "\033[1;33m#{?pane_active,*, }\033[m:#I.#P:#{pane_current_command}:\033[1;30m#{?#{==:#W,#{pane_current_command}},,(#W)}\033[m:#{?window_linked,\033[1;36m[linked]\033[m,}"|column -ts":" -o" "|while read -r l;do echo "$l";done',
        \ 'sink': function('s:VimuxSetPane'),
        \ 'options': "--prompt 'Vimux Pane> ' --delimiter='[* ]+' --nth=2.. --ansi --no-info --preview='tmux capture-pane -ep -t {2}|cat -s|tail -n $(tput lines)' --preview-window=up,70%"}
  call fzf#run(opts)
endfunction

command! -nargs=0 FZFVimuxPickPane call s:VimuxPickPaneFzf()

@andrewdollard
Copy link

Thank you for this! This PR fixes an ongoing headache in my workflow. Would love to see this PR get merged.

if existingId !=# ''
if !exists('g:VimuxRunnerIndex') && existingId !=# ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about calling s:hasRunner()?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry I'm thinking of the version I've got sitting in #237. I'll take a closer look at this.

Copy link
Member

@mvanderkamp mvanderkamp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think VimuxTogglePane is broken at the moment for this workflow.

I really like the use of -a for tmux list-panes. It has me wondering if we could simplify the plugin by always tracking a pane ID. At the moment, commands can be issued to the wrong pane in a window runner if there are multiple panes in the window, and this seems like a good way of resolving that while also potentially simplifying the code.

I don't think that should be done in this PR though.

As for toggling not working, since using a runner pane from a different window or session is a new workflow, I think it's probably not critical to support it. Can you take a look to see if there's a simple solution though?

Comment on lines -332 to +333
return match(VimuxTmux('list-'.runnerType."s -F '#{".runnerType."_id}'"), a:index)
let allPanes = runnerType ==# 'pane' ? '-a ' : ''
return match(VimuxTmux('list-'.runnerType."s ".allPanes."-F '#{".runnerType."_id}'"), a:index)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tmux list-windows supports -a as well, is there a reason why we shouldn't use it for window runners?

@3ximus
Copy link
Author

3ximus commented Jul 11, 2025

I didn't know about the existence of VimuxTogglePane, it's not documented, and it doesn't really make sense to me to have something like that on this plugin. In what scenario is it of use to you as opposed to zooming or break the pane?

For that reason I don't feel like digging too much into the issue but putting this at the beginning of the function at least prevents the error:

function! VimuxTogglePane() abort
  if exists('g:VimuxRunnerIndex') && g:VimuxRunnerIndex !=# ''
    ...

Regardless, I agree with you that it might not be a necessity to make VimuxTogglePane work in this PR, and using the global pane id to identify the pane would definitely make it simpler to manage that function.

Copy link
Member

@mvanderkamp mvanderkamp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know about the existence of VimuxTogglePane, it's not documented, and it doesn't really make sense to me to have something like that on this plugin.

It's not something I use either, but that doesn't mean no one does. I imagine someone might like to "unclutter" their window from time to time by sending their runner away without closing it or having to zoom in to just one pane. In any case the command has been around for over a decade now so I don't want to break anyone's workflow. It should be documented though, that's a fair point.

I think for this PR just update the hasRunner changes so that it uses -a for both panes and windows and I'll merge this in.

Odd that checks haven't run on this PR though, maybe they will when you push another commit?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants