hharnisc / hypercwd

Opens new tabs with the same directory as the current tab in Hyper
MIT License
383 stars 39 forks source link

Support for Bash on the Windows Subsystem for Linux? #16

Open JacobDB opened 7 years ago

JacobDB commented 7 years ago

Running Hyper with Bash on WSL as the specified shell in .hyper.js, this extension doesn't work properly. It just opens in the user directory as usual.

Would you be able to add support for Bash on WSL?

danieltanfh95 commented 7 years ago

I did some hacking yesterday to see if the command could be changed to use the windows toolchain instead. I noticed that the pid passed into https://github.com/hharnisc/hypercwd/blob/master/index.js is not the process id of hyper itself, so it can't be used to identify the session, unless there is a way to map that into a process id.

Also note that since hyper is launched from windows, the node module hypercwd is also launched from windows.

I probably need to look into the hyper code to know what id are they passing around.

I'm just using echo $PWD | clip on git-bash then <c-t>cd<c-v> as a work around instead. (I'm also using https://github.com/xilun/cbwin)

hharnisc commented 6 years ago

Hey @JacobDB and @Shadowys I added support for Windows recently, could you try this pluggin again - not sure if it gracefully handles Bash on the Windows Subsystem 😄

JacobDB commented 6 years ago

@hharnisc just had a chance to test today, doesn't appear to work with bash. I even tried re-installing all modules, no dice.

hharnisc commented 6 years ago

Thank you for trying this out @JacobDB - I wonder did it complain about lsof not being a command on the console? If it didn't that must mean that the detected environment is win32 :thinking:

JacobDB commented 6 years ago

I don't see any errors like that, but this morning I am seeing this error when trying to open a new tab; not sure if it's related.

image

Seems to be weirdly intermittent, can't get it to happen after re-opening Hyper. Will update if I figure out what causes it.

danicatalan commented 6 years ago

@hharnisc @JacobDB

I also installed hypercwd with hpm inside WSL and it opens the HOME path, not the current working directory.

Opening a new tab is not throwing any JS error here (still not opening the cwd), but I will report in case it happens to me.

danicatalan commented 6 years ago

I'm starting to get the same alert while trying to split:

screenshot 11

JacobDB commented 6 years ago

Yea, it seems fairly intermittent. It happens most often when gulp watch is running on one of my projects.

hharnisc commented 6 years ago

Sharing some context here about how the working directory is detected, on OS X it uses the lsof command and on Windows it uses a regex on the I/O. (since under standard windows shell it outputs that after each command)

Windows Regex: https://github.com/hharnisc/hypercwd/blob/master/index.js#L13

My guess what is happening here is that hypercwd is detecting windows but then doesn't detect the working directory because bash doesn't output that after each command.

danicatalan commented 6 years ago

Thanks for the feedback @hharnisc. I can't really help here fixing this issue because of my limited background, but I will share some information about how I'm using cwd now hoping this has some value for you to keep working on this.

As my shell is zsh and I'm using oh-my-zsh, I can use a plugin called last-working-directory that stores the last path in cache (I think it writes the path on a file everytime I cd on my term).

This plugin implements the $ lwd command to cd the path stored in that cache file.

So, with that command available, I setup my shell to manually $ lwd every time I start a new session (no matter if I just opened Hyper, a new tab or splited). It smells but it works as expected.

enwin commented 6 years ago

Hi everyone,

I just switched to Windows and WSL and I'm facing the same issue.

In hyper I'm running zsh with the following .hyper.js config:

  shell: 'C:\\Windows\\System32\\bash.exe',
  shellArgs: ['-c', 'zsh']

I did some digging into hyper and hypercwd and yes hypercwd is detecting windows because hyper is running on windows. We could use exec() but unfortunately nodejs' child_process is bound to cmd instead of the running shell. I'm able to exec() into bash but of course it spawns a new instance instead of the running one.

If hyper was able to give access to session.pty on SESSION_ADD in addition to session.pty.pid as we can see in window.js it would be possible to find the current session and access the running shell (its pty) to exec() some pwd command to use in the new tab.

I might fork hyper to test this but wouldn't mind some feedback beforehand.

Cheers

JacobDB commented 6 years ago

Any progress on getting this working?

hharnisc commented 6 years ago

Hey @JacobDB :wave: I've added a help wanted badge on this one. I don't have enough time to fully implement this, but would accept a patch from the community. Probably better someone else do this since I'm not a daily user of this setup :smile:

Stanzilla commented 6 years ago

@hharnisc this might help? https://github.com/henrikdahl/hyper-statusline/pull/73

pevecyan commented 6 years ago

@Stanzilla I don't think that will help, I am just ignoring commands in wsl bash

rfgamaral commented 6 years ago

@enwin Have you tried what you said earlier?

If hyper was able to give access to session.pty on SESSION_ADD in addition to session.pty.pid as we can see in window.js it would be possible to find the current session and access the running shell (its pty) to exec() some pwd command to use in the new tab.

I forked hyper to share session.pty and I now have access to that object but I'm not sure exactly what do with it. How do you exec something like pwd with that pty object? I'm a bit clueless.

However, everything is supposed to be private (judging by the _ prefixes):

image