hangxingliu / wslgit

:candy: Use Git installed in WSL(Windows Subsystem for Linux) from Windows and Visual Studio Code
GNU General Public License v3.0
150 stars 18 forks source link

Make WSL bash execute .bashrc (to support ssh-agent) #12

Closed rennex closed 5 years ago

rennex commented 5 years ago

I had to make this change to enable using ssh-agent which I have configured in .bashrc (according to GitHub's instructions, which I guess describes the common technique). This enables pushing to and pulling from remote repos using ssh keys, without leaving a passwordless ssh key on your disk.

A simple wsl some commands in cmd.exe doesn't seem to make bash run .profile, .bash_profile, nor .bashrc, so running wsl bash -ic 'some commands' looks like the only solution.

These changes seemed to work for me, but feel free to re-think it, make it configurable, or something. But I think something like this needs to be implemented.

hangxingliu commented 5 years ago

I think it will be better if implemented like following snippet:

fn use_interactive_shell() -> bool {
    // check for explicit environment variable setting
    if let Ok(interactive_flag) = env::var("WSLGIT_USE_INTERACTIVE_SHELL") {
        if interactive_flag == "false" || interactive_flag == "0" {
            return false;
        }
    }
    // check for advanced usage indicated by BASH_ENV and WSLENV=BASH_ENV
    else if env::var("BASH_ENV").is_ok() {
        if let Ok(wslenv) = env::var("WSLENV") {
            if wslenv.split(':').position(|r| r.eq_ignore_ascii_case("BASH_ENV")).is_some() {
                return false;
            }
        }
    }
    true
}

https://github.com/andy-5/wslgit/blob/master/src/main.rs#L96