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

TmuxPaneCurrentCommand returns nothing on Windows-bash #163

Closed
ColinKennedy opened this issue Jan 22, 2017 · 17 comments
Closed

TmuxPaneCurrentCommand returns nothing on Windows-bash #163

ColinKennedy opened this issue Jan 22, 2017 · 17 comments

Comments

@ColinKennedy
Copy link

I'm using Window 10 (64bit) and running Ubuntu bash using the Windows 10th anniversary edition update. I have a full install of Vim 8.0 in both Windows and bash (Windows is 64 bit, the bash is Vim Huge version - it is not 64 bit if that's relevant). All plugin keys are at their default mappings and I've cleared out my .vimrc for testing.

When I run vim-tmux-navigator in bash, I can navigate from tmux to vim and back with no issues. I cannot move between Vim buffers though with the hotkeys. I can do it if I write the commands out explicitly :TmuxNavigateLeft/Up/Down/Right/Previous though.

On windows, the hotkeys works perfectly. I saw the note about TmuxPaneCurrentCommand online and figured I'd post about it. Do you have any advice on why this could be happening?

@christoomey
Copy link
Owner

My guess is that the process detection we're using to determine if Vim is the current process is not working on your version of bash. You can confirm this by changing out the tmux mappings for the ones using the older configuration: https://github.com/christoomey/vim-tmux-navigator/tree/33d688a028cd9d5f3ab8a4d994dbe14b8e13e55e#tmux.

@blueyed
Copy link
Collaborator

blueyed commented Jan 22, 2017

btw: is TmuxPaneCurrentCommand still relevant after all? (it was only with the old method, and appears to be empty for OP?!)
Anyway, you can use :debug TmuxPaneCurrentCommand to see what is being executed in the end: use s to step and echo X to display variable X - but I do not think it is too relevant here.

I guess you have to debug what in the process goes wrong, assuming you're using

is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
    | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"

from

is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
| grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
.

Try running it manually, e.g. ps -o state= -o comm= -t '$TMUX_PANE', after suspending Vim (Ctrl-z).

@kevin-king
Copy link

Entering Debug mode.  Type "cont" to continue.
cmd: TmuxPaneCurrentCommand
>
cmd: call s:TmuxPaneCurrentCommand()
>
function <SNR>35_TmuxPaneCurrentCommand
line 1: echo s:TmuxCommand("display-message -p '#{pane_current_command}'")
>
function <SNR>35_TmuxPaneCurrentCommand..<SNR>35_TmuxCommand
line 1: let cmd = s:TmuxOrTmateExecutable() . ' -S ' . s:TmuxSocket() . ' ' . a:args
>
function <SNR>35_TmuxPaneCurrentCommand..<SNR>35_TmuxCommand..<SNR>35_TmuxOrTmateExecutable
line 1: return (match($TMUX, 'tmate') != -1 ? 'tmate' : 'tmux')
>
function <SNR>35_TmuxPaneCurrentCommand..<SNR>35_TmuxCommand..<SNR>35_TmuxOrTmateExecutable
line 1: End of function
>
function <SNR>35_TmuxPaneCurrentCommand..<SNR>35_TmuxCommand..<SNR>35_TmuxSocket
line 2: return split($TMUX, ',')[0]
>
function <SNR>35_TmuxPaneCurrentCommand..<SNR>35_TmuxCommand..<SNR>35_TmuxSocket
line 2: End of function
>
function <SNR>35_TmuxPaneCurrentCommand..<SNR>35_TmuxCommand
line 2: return system(cmd)
>
function <SNR>35_TmuxPaneCurrentCommand..<SNR>35_TmuxCommand
line 2: End of function
>
bash
function <SNR>35_TmuxPaneCurrentCommand
line 1: End of function
>

@blueyed
Copy link
Collaborator

blueyed commented Jan 24, 2017

No echos/feedback in there.. and I still think TmuxPaneCurrentCommand is obsolete.

Please try the ps based debugging.

@blueyed
Copy link
Collaborator

blueyed commented Jan 24, 2017

From above :echo match($TMUX, 'tmate') might be interesting.

@kevin-king
Copy link

Sorry, new to this kind of debugging. Here's some echos:

Entering Debug mode.  Type "cont" to continue.
cmd: TmuxPaneCurrentCommand
>
cmd: call s:TmuxPaneCurrentCommand()
>
function <SNR>35_TmuxPaneCurrentCommand
line 1: echo s:TmuxCommand("display-message -p '#{pane_current_command}'")
>
function <SNR>35_TmuxPaneCurrentCommand..<SNR>35_TmuxCommand
line 1: let cmd = s:TmuxOrTmateExecutable() . ' -S ' . s:TmuxSocket() . ' ' . a:args
>echo $cmd
>s
function <SNR>35_TmuxPaneCurrentCommand..<SNR>35_TmuxCommand..<SNR>35_TmuxOrTmateExecutable
line 1: return (match($TMUX, 'tmate') != -1 ? 'tmate' : 'tmux')
>echo $TMUX
/tmp/tmux-1000/default,12058,0
>echo match($TMUX, 'tmate')
-1
>s
function <SNR>35_TmuxPaneCurrentCommand..<SNR>35_TmuxCommand..<SNR>35_TmuxOrTmateExecutable
line 1: End of function
>
function <SNR>35_TmuxPaneCurrentCommand..<SNR>35_TmuxCommand..<SNR>35_TmuxSocket
line 2: return split($TMUX, ',')[0]
>echo split($TMUX, ',')[0]
/tmp/tmux-1000/default
>s
function <SNR>35_TmuxPaneCurrentCommand..<SNR>35_TmuxCommand..<SNR>35_TmuxSocket
line 2: End of function
>
function <SNR>35_TmuxPaneCurrentCommand..<SNR>35_TmuxCommand
line 2: return system(cmd)
>
function <SNR>35_TmuxPaneCurrentCommand..<SNR>35_TmuxCommand
line 2: End of function
>
bash
function <SNR>35_TmuxPaneCurrentCommand
line 1: End of function
>

@kevin-king
Copy link

By suspend VIM, do you mean run :debug TmuxPaneCurrentCommand and while its on breakpoint, execute ps -o state= -o comm= -t '$TMUX_PANE'? Tried that and not getting any output to console.

@blueyed
Copy link
Collaborator

blueyed commented Jan 24, 2017

What is cmd in function <SNR>35_TmuxPaneCurrentCommand..<SNR>35_TmuxCommand - line 2: return system(cmd)?

No, the ps thing works in general.. but you should get the right $TMUX_PANE.
But suspending might even interfere, so do it from another pane, but with $TMUX_PANE from the Vim window.

@kevin-king
Copy link

function <SNR>35_TmuxPaneCurrentCommand..<SNR>35_TmuxCommand
line 2: return system(cmd)
>echo $cmd
>s
function <SNR>35_TmuxPaneCurrentCommand..<SNR>35_TmuxCommand
line 2: End of function

@kevin-king
Copy link

My vim $TMUX_PANE is %0. Tried running ps -o state= -o comm= -t '%0' from $TMUX_PANE %1 and still nothing.

@blueyed
Copy link
Collaborator

blueyed commented Jan 24, 2017

Ohoh, I've mixed up tmux pane and tty. (tmux -t expects the output from tty - IIRC).
Can you figure it out and update your report?

@ErnWong
Copy link

ErnWong commented Mar 18, 2017

Hey @blueyed mind if I step in and revive this discussion?

On my Bash on Ubuntu on Windows, the ps command returns this:

$ ps
  PID TTY          TIME CMD
    2 ?        00:00:01 bash
   87 ?        00:00:00 tmux
   89 ?        00:00:29 tmux
  144 ?        00:00:05 bash
  233 ?        00:00:02 bash
 4757 ?        00:01:51 vim
 4832 ?        00:00:03 bash
 4958 ?        00:00:01 bash
 5047 ?        00:00:34 htop
 7642 ?        00:00:00 man
 7653 ?        00:00:00 pager
 8018 ?        00:00:01 bash
 8178 ?        00:00:00 ps

tty on my suspended vim pane gives:

$ tty
/dev/pts/1

However, like @kevin-king , I get no output from ps:

$ ps -t '/dev/pts/1'
  PID TTY          TIME CMD
$

It looks like ps is not behaving correctly... a bug with Bash on Windows?

(Probably relevant comment from microsoft/WSL#482 (comment))

TTY is showing up as a '?' which is caused by us not having a /proc/tty directory.

@blueyed
Copy link
Collaborator

blueyed commented Mar 19, 2017

@ErnWong
What does :display '#{pane_tty}' in tmux display?

Anyway, I think your workaround would be to not limit it to the current pane's tty (i.e. remove the -t '#{pane_tty}' from the ps:

is_vim="ps -o state= -o comm=  \
    | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"

@ErnWong
Copy link

ErnWong commented Mar 20, 2017

Let me check.... :display '#{pane_tty}' gives me /dev/pts/1

In the workaround, won't removing the tty filter make all the tmux panes think they're running vim? I gave it a try and I couldn't navigate between tmux panes using the C-hjkl keys.

Typing this in a non-vim pane:

ps -o state= -o comm= | grep -iE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'

and typing this inside vim:

:!ps -o state= -o comm= | grep -iE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'

both gives S vim (the -q grep option is removed for debugging purposes).

Yeah, suspending vim to test stuff does interfere because suspending gives vim a 'T' state (at least on my machine), and our grep regex is designed to ignore them.

But otherwise yup, thanks, removing the tty filter does make my vim navigation work again in the short term. In my free time, I might experiment with stuff and see if I can get a test that works on my machine. No guarantees, though, because I'm very inexperienced with linux.

I'm sorry for replying so late. Our timezones are slightly out of phase 😏

@ErnWong
Copy link

ErnWong commented Mar 20, 2017

Hey @blueyed, I somehow managed to get a test script working on my machine!

It's a bit... less elegant than the original, and haven't been stress-tested yet, let alone tested on other platforms.

is_vim="ps -o state= -o comm= -o pid= \
      | grep -iE '^[^TXZ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)? +(\\S+\\/)?[0-9]+$' \
      | sed 's/^.* \\([0-9]*\\)$/\\/proc\\/\\1\\/fd\\/0/g' \
      | xargs -n1 readlink \
      | grep -q '#{pane_tty}'"  

It's surprising what can be learned by reading the source code of emscripten.

@ErnWong
Copy link

ErnWong commented Jul 25, 2017

Great news! I've just installed Creators Update for Windows 10, and the provided vim-tmux-navigator plugin now works on my machine inside bash on ubuntu on windows.

@christoomey
Copy link
Owner

Hey @ErnWong, thanks for updating and glad to hear things are working for you now! I'm going to close this now as it sounds like the version was the main issue, but please do update if you discover anything else.

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

No branches or pull requests

5 participants