Coder Social home page Coder Social logo

watzon / wsl-proxy Goto Github PK

View Code? Open in Web Editor NEW
141.0 12.0 25.0 31 KB

WSL proxy files for editor/linux interop

License: Do What The F*ck You Want To Public License

Batchfile 70.01% Shell 29.99%
wsl wsl-proxy linux atom linter php visual-studio-code sublime-text sublime-text-3 windows

wsl-proxy's Introduction

WSL Proxy Files

WSL (Windows Subsystem for Linux) is an awesome bit of innovation by Microsoft that allows you to run Linux inside of Windows 10 without the need for a Virtual Machine. This has several benefits, the largest of which is the memory that you save by not running a whole secondary OS. Unfortunately it also has it's drawbacks, the biggest of which is a distinct lack of support through editors such as Atom, VSCode, and Sublime Text.

The goal of this project is to create a collection of "proxy" batch files that can be used to route requests to the linux version of a command. Almost all of the files will have the same layout

@echo off
bash.exe -c "php %*"

As an example usecase take the atom-linter package. Most of the linters, such as linter-php require the path to an executable in order to run. If that executable is inside of WSL however, there is no way to access it.

Using the wsl-proxy php.bat file however, you can just replace the path to the executable with C:\\Users\\myuser\\path\\to\\wsl-proxy\\php.bat. Requests are now being routed to the linux version of PHP.

Pro tip: If you clone this and add the cloned directory to your windows PATH you will be able to access any of the proxied commands through command prompt (even without the .bat extension)

Note: This is an experiment currently and I can't guarentee it will work with everything, but please feel free to add files here. Let's turn this into a one-stop shop for wsl-proxy files.

Auto-generating proxy files

Run the proxygen.cmd script to automatically generate proxies. A subfolder named .\autogen will be created, and all the autogenned proxy files will be placed here -- add this folder to your Windows PATH if you want access to the proxied commands without typing in a full path.

Usage:

  • (No args): proxygen
    Prompts you to enter program names from stdin (press CTRL-D when done).
  • (Redirect from file): proxygen < program_name_file
    Same as above, but reads program names from a file.
  • (Specify args on command line): proxygen program1 program2 ...

Examples:
proxygen gcc g++
proxygen /usr/bin/foo
proxygen /usr/bin/*
proxygen /usr/bin/* /bin/*

Program names will be resolved to absolute paths. If a program is not found, a warning message will be displayed (the proxy will still be created).

wsl-proxy's People

Contributors

benjamind avatar flowstatedev avatar krosf avatar lejmr avatar longstorymedia avatar oatelaus avatar trusted-contract avatar watzon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wsl-proxy's Issues

Windows paths?

Hey there, this is a cool project, however I'm not entirely sure about file path translation, currently I'm doing some dirty stuff to hand the correct paths over to the WSL side. For example, here's my php-cs-fixer.bat file:

php-cs-fixer.bat:

@echo off

SET "fix_file=%1"

for /f %%i in ('convert_path %fix_file%') do set file_path=%%i

bash.exe -c "~/.composer/vendor/bin/php-cs-fixer fix %file_path% --rules=@PSR2"

@echo on

And here's what I have to do to convert the paths from Sublime Text's $file and $folder parameters:

convert_path.bat:

@echo OFF

set "variable=%1"

set "drive=%variable:~0,1%"

set variable=%variable:~2%
set "variable=%variable:\=/%"

if %drive%==C set "drive=c"
if %drive%==D set "drive=d"
if %drive%==E set "drive=e"

set "variable=/mnt/%drive%%variable%"

echo "%variable%"

@echo ON

Which translates C:\Path\to\file.php to /mnt/c/Path/to/file.php but is extremely gross. Is there a better way to achieve this? Do I have to do this for each proxy?

The other issue is that I cannot just call any Composer packages directly from bash.exe -c, I get this error: /bin/bash: phpcs: command not found, however when I call bash.exe -c "~/.composer/vendor/bin/phpcs %*" instead it works. Is there any way to get this to work like the former with global Composer files?

Unable to run WSL programs

I found an error I guess, there is problem with executing command on bash.exe. If yiu use only bash.exe -c "java %*" it will give you an error: /bin/bash command not found. Fix for that is simple, just add -i option.

I am using Pengwin(WLinux)

automatically collect proxies

It wouldn't be too hard to write something to go through the results of wsl ls /usr/bin and format them as individual batch files. If I have time I might try this out, otherwise you're welcome to it ;)

Can't get git.bat to work

I'm having trouble getting this fix to work. I first tried just downloading git.bat and setting git.path in vscode to C:\Users\my\path\to\git.bat. That didn't work -- vscode still thinks that git needs to be installed. I then cloned the whole project and added it to my windows path variable as suggested. That didn't fly either. I'm a bit stuck.

I think it would be good to point out/have an example of how and which settings to change to get Windows to look at the .bat file as if it were an executable. Mind helping me out?

Thanks

add C/C++

I tried to get C linter to work but I would find the errors. I am using linter-gcc by hebaishi.
I tried a batch file with the code bellow:
@echo off
bash.exe -c "gcc %*"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.