From 8199bb72b9b4c139eae8e6ce82013ce9dabcdffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20A=C5=ADtu=C5=A1ka?= Date: Tue, 9 Sep 2025 00:52:39 +0300 Subject: [PATCH 1/2] search for a pane that runs shell and can take a command --- plugin/vimux.vim | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/plugin/vimux.vim b/plugin/vimux.vim index b5000a7..85f7e83 100644 --- a/plugin/vimux.vim +++ b/plugin/vimux.vim @@ -300,6 +300,11 @@ function! s:existingRunnerId() abort return '' endfunction +function! s:isPaneAvailable(paneId) + let currentCmd = VimuxTmux('display-message -p -t ' . a:paneId . ' "#{pane_current_command}"') + return match(currentCmd, '\v(bash|zsh|sh|fish)') != -1 +endfunction + function! s:nearestRunnerId() abort " Try finding the runner in the current window/session, optionally using a " name/title filter @@ -314,8 +319,13 @@ function! s:nearestRunnerId() abort " '1:' is the current active pane (the one with vim). " Find the first non-active pane. for view in views + let runnerId = split(view, ':')[1] + if runnerType ==# 'pane' && !s:isPaneAvailable(runnerId) + continue + endif + if match(view, '1:') ==# -1 - return split(view, ':')[1] + return runnerId endif endfor return '' From f7898ff1dc568ca082164b9a7896d380b9b03412 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20A=C5=ADtu=C5=A1ka?= Date: Tue, 9 Sep 2025 00:55:26 +0300 Subject: [PATCH 2/2] when looking for the nearest runner prioritize the one that was used last --- plugin/vimux.vim | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugin/vimux.vim b/plugin/vimux.vim index 85f7e83..4efede5 100644 --- a/plugin/vimux.vim +++ b/plugin/vimux.vim @@ -310,15 +310,15 @@ function! s:nearestRunnerId() abort " name/title filter let runnerType = VimuxOption('VimuxRunnerType') let filter = s:getTargetFilter() + let lastField = runnerType ==# 'pane' ? 'pane_last' : 'window_last_flag' + let format = " -F '#{".runnerType."_active}:#{".runnerType."_id}:#{".lastField."}'" let views = split( - \ VimuxTmux( - \ 'list-'.runnerType.'s' - \ ." -F '#{".runnerType.'_active}:#{'.runnerType."_id}'" - \ .filter), + \ VimuxTmux('list-'.runnerType.'s' . format . filter), \ '\n') + let last_runner_first = sort(views, {a, b -> str2nr(split(b, ':')[2]) - str2nr(split(a, ':')[2])}) " '1:' is the current active pane (the one with vim). " Find the first non-active pane. - for view in views + for view in last_runner_first let runnerId = split(view, ':')[1] if runnerType ==# 'pane' && !s:isPaneAvailable(runnerId) continue