Open jrock2004 opened 6 years ago
Yeah, status line is not working on wsl yet
What kind of work would this need to get it working under WSL?
I've been trying to get this plugin working with WSL and it's not as easy as I though. Let me walk you through my thought process, what I've achieved already and the problems with my approach.
For all this to work there's a bunch of things that need to happen only if the active shell is a WSL. My approach to know that is simple, as long as zeit/hyper#3046 is merged. We start with this:
Now, for WSL we cannot rely on Node's exec
because that will run cmd.exe
on Windows and that doesn't help us at all, we need to run bash.exe -ic "{cmd}"
instead. My approach for that:
And that's our first problem, Interop between Windows and WSL, which is a bit slow. We're spwaning a new command with exec
, which is WSL's bash, which in turn will run a command inside WSL.
Given the change above we are now going to run all our commands inside WSL, meaning the PID used by lsof
commands needs to be the correct one:
Here I have to run lsof
as soon as SESSION_ADD
event is fired to read the active shell bash PID and store it for future reference, associated to the active shell UID. After this change you'll notice that the status line already shows the current path and if you cd
to a different path, you'll see it change, albeit a bit slow because of the whole exec
» bash
» lsof
thing.
Now we need to handle all the Git commands that are executed through the whole plugin. The problem with those when running WSL is that although they still run with exec
» bash
» git
, exec
still runs under Windows and the cwd
optional parameter is getting WSL paths. We need to convert those:
So, before running exec
» bash
» git
we need to run exec
» cmd
» wsl wslpath
to get the proper Windows path to pass down to the other command. After this point, and if you wait a while, you'll notice the status line will now include Git related information (if you are on a path with a Git repository that is).
However, it's quite slow because for each cd
change, or even each command typed into the Hyper terminal, there's a lot of exec
» bash
» git
and exec
» cmd
» wsl wslpath
going around. Hyper even starts to break once you star to type on your terminal all sorts of commands because there's a lot of background processing with all those commands.
Even if this was fast enough, the work to get hyper-statusline
to support WSL is not yet done. You might have noticed that paths in the status line have the wrong path separator, this is due to:
tildify
is a package that converts an absolute path to tilde path and uses path.sep
to get the correct separator for the OS where it's running the problem is that we are running Windows, but we want the Linux path separator because this is WSL.
There's also a problem with the home folder, which should be replaced with ~
but again, the home folder detected by tildify
(which uses os-homedir
for this) is the Windows one and not the WSL one.
The last thing that I remember that is missing to fix all WSL issues is opening Windows Explorer in the correct path when clicking the status line path element.
Everyone feel free to pitch with suggestions and improvements so we can get WSL support into hyper-statusline
.
I've made a small improvement to the implementation above:
Instead of getting converting a WSL path to a Windows path multiple times (per each Git command invocation, basically), now it's converted only once before invoking the setGit
function.
This improves performance a bit but not enough...
This can easily be tested by launching Hyper and as soon as WSL is ready, just press Return a bunch of times in succession. Look at the task manager and you'll see the Electron process eating all the CPU with too many Microsfot Bash Launcher
, Microsoft Windows Subsystem for Linux Background Host
and Windows Command Processor
running.
Oh, well...
Made two small improvements and fixed a new found issue at the same time:
Forced WSL bash commands to run in non-interactive mode, speeding up all commands a bit.
Instead of passing the current working directory to exec
, pass it to Git instead. This is faster since we no longer have to use wsl wslpath
to convert between WSL/Windows paths and at the same time allows the plugin to keep working for every path (previous implementation wouldn't work if you had a Git repository on a path other than /mnt/<drive>/*
.
This is still too slow because for every command typed into the Hyper terminal, a lot of bash -c "<cmd>"
s are executed and Windows/WSL interoperability is still a bit slow. Not sure how can this be improved from the plugin side :/
I think perhaps we should run a helper inside of WSL that broadcasts on an e.g. Unix Socket. Windows can read the Unix Socket file to get the latest information and then draw it that way.
It looks like it half works now. its dumping errors to the status bar line, but not git info. Is this being actively looked into or has it been determined to be too difficult?
@rfgamaral : any updates on this thread/PR?
I'm no longer working on it, I couldn't find a reliable solution.
I am using hyper with WSL on Windows 10. All I see an empty status bar