Skip to content

Instantly share code, notes, and snippets.

@larsonmars
Last active February 16, 2019 16:25
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larsonmars/bf9b691c359bbd4be31e1e1e36277bbf to your computer and use it in GitHub Desktop.
Save larsonmars/bf9b691c359bbd4be31e1e1e36277bbf to your computer and use it in GitHub Desktop.
WSL windows to linux path converter
/* w2lp.c
*
* 2017 by Lars Stockmann
* released in the public domain
*/
#include <stdio.h>
#define PRE_PATH "/mnt/"
int main(int argC, const char* argV[])
{
FILE* out = stdout;
int i, errC = 0;
for (i = 1; i < argC; ++i) {
const char* pSrc = argV[i];
int c = *pSrc++;
if (c < 'a')
c += 'a' - 'A';
if (c < 'a' || c > 'z' || *pSrc++ != ':') {
++errC;
continue;
}
if (i > 1)
putc(' ', out);
fwrite(PRE_PATH, 1, sizeof PRE_PATH - 1, out);
putc((char)c, out);
while((c = *pSrc++))
putc(c == '\\' ? '/' : (char)c, out);
}
putc('\n', out);
return errC;
}
@larsonmars
Copy link
Author

larsonmars commented Nov 2, 2017

Allows you to drag & drop windows files in the bash

  • copy to /usr/local/bin
  • make it executable (chmod a+x)
  • use it for example like this ls "$(w2lp 'drag&drop windows file')"

@strarsis
Copy link

strarsis commented Nov 2, 2017

@larsonmars: A dedicated GitHub repository with Makefile / packaging would be awesome 👍

@larsonmars
Copy link
Author

I thought it is too simple to be worthy a repository, but if you think it's worth, I can see what I can do. Note that I just more or less followed the msdn blog to build it using visual studio, specifically targeting WSL, which was really easy.

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