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

doesn't work with git bash #33

Open
pikilon opened this issue Oct 27, 2017 · 7 comments
Open

doesn't work with git bash #33

pikilon opened this issue Oct 27, 2017 · 7 comments

Comments

@pikilon
Copy link

pikilon commented Oct 27, 2017

A lot of are using git bash to have a similar bash as in linux, configuring hyper like this
vercel/hyper#1252 (comment)

But this "must to have" plugin doesn't work sadly

No errors, nothing

@burnedikt
Copy link

burnedikt commented Feb 8, 2018

I would also love to see this and took a short look but the general problem is that I haven't found a straight-forward way to get the current working direcotry of a running git-bash session.

The windows specific code of setCwd in lines 17 - 28 assumes that the action.data will contain some information about the current directory but in my tests, it didn't.

A sample that i got for the action.data is

�[0m�[0K�]0;MINGW64:/c/Users/anonymous��[?25l�[0;32manonymous@DESKTOP-ANONYMOUS �[0;35mMINGW64 �[0;33m~�[0m�[0K�[1A�[?25h�[?25l$�[0K�[3G�[?25h

which only contains the path to the home directory (in this case /c/Users/anonymous) (which appears to be the working directory of git-bash.exe) but not the actual working directory that the bash (sh.exe) uses.

Any ideas on how to get the actual working directory?

@devjosh-mudbath
Copy link

+1

1 similar comment
@Spiderpig86
Copy link

+1

@codehearts
Copy link

I was able to get the cwd using cygwin32 on Windows 7.

exec(`readlink -e /proc/${pid}/cwd`, (err, stdout) => {
  const cwd = stdout.trim();
  /* ... */
}

I'm not sure if this would work for Git Bash or MinGW

@burnedikt
Copy link

@codehearts Thanks! Finally found the time today to try out your solution. The good news is, the solution works in Git Bash / MinGW to get the cwd. The bad news is that it (obviously) only works if you know the exact pid of the bash (bash.exe) that is currently running within the "git-bash-wrapper" (git-cmd.exe). However, when using git-bash with hyper, as of now it is the only way to use the "wrapper" as the shell and have it launch the bash internally as shown in the sample configuration. So I guess we're back to square one here...

@rofrol
Copy link

rofrol commented Jun 7, 2018

@burnedikt I don't use wrapper on Windows 10.

    shell: 'C:\\Program Files\\Git\\bin\\bash.exe',

    // for setting shell arguments (i.e. for using interactive shellArgs: `['-i']`)
    // by default `['--login']` will be used
    shellArgs: ['--login'],

@burnedikt
Copy link

burnedikt commented Jul 2, 2018

@rofrol Thanks, didn't know that worked. Either way, it did not help with the problem per se. Nevertheless, I've got a few steps further. Maybe this helps someone else:

  1. Whenever a tab is cloned or split vertically / horizontally, what we get from hyper is the PID of the git-bash. This may be either git-cmd.exe, git-bash.exe, or as in @rofrol's case bash.exe. However, it is never the PID of the actual bash process (usr/bin/bash) which we need to find out the current working directory using the method @codehearts posted above.
  2. To get the actual bash process (/usr/bin/bash) from the wrapping git-bash process's PID, we can use wmic which allows us to find child processes of the wrapping git-bash process, i.e. the /usr/bin/bash process.
  3. As soon as we got the actual bash process's PID, we can use readlink -e on /proc/${processId}/cwd to find the cwd of this bash

Coming this far, I've noticed some flaws in the current windows-specific code of hypercwd, namely that the code in windowsActionHandler.js#L30-L34 never passes the original bash session's PID to the windowsSetCwd function but only the PID of the newly created bash process. Obviously, the PID of the newly created bash session is irrelevant, since we need the cwd of the previous session. The fix for this is easy enough, though I am not sure as to what the side effects are regarding non-git-bash-shells.

Even then, we face one last problem: We know the running bash processes (both of git-bash and actual bash) and we know the cwd we want to set for this bash process but how do we set the current working directory for a bash process that is already running? There are some approaches but it seems more reasonable to pass the cwd already, before the session is even started / the new tab is created. Needless to say, the Action SESSION_SET_CWD does not work as expected.

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

No branches or pull requests

7 participants