Skip to content

Instantly share code, notes, and snippets.

@Erisa
Last active October 26, 2021 20:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Erisa/836fc540dfe20016046b958556fb1c43 to your computer and use it in GitHub Desktop.
Save Erisa/836fc540dfe20016046b958556fb1c43 to your computer and use it in GitHub Desktop.
WSL wrapper that runs commands in WSL context with paths converted. For PERSONAL use.
@echo off
REM change this files filename to the name of the program you want to launch.
REM for example if its called 'ssh.bat' it will run ssh in wsl when launched.
REM w.exe is w.js but built with 'npm i -g pkg' and 'pkg w.js -t host'
REM you could also just use node normally but i'm weird.
\path\w.exe %~n0 %*
@echo off
set args=
:loop
REM Windows Terminal needs a title before it will load i ts default, thanks Windows.
title SSH Wrap -- Connecting
ssh %args% %*
REM Might as well make the most of it.
title SSH Wrap - Disconnected
set /p args="[Process terminated. Press enter to retry or give extra args]: "
goto loop
// fork of https://github.com/snooopcatt/wslnodejs
// code here is for PERSONAL USE and is only made public for reference purposes.
// if your computer explodes it is NOT my fault.
var args = process.argv.map(arg => {
let result = arg.replace(/\\/g, '/')
.replace(/([A-Za-z]):/, '/mnt/$1')
.replace(/\/mnt\/\w/, s => s.toLowerCase())
.replace(/'/, "\\'");
if (/\/mnt\//.test(result)) {
result = `"${result}"`;
}
return result;
});
const { spawnSync, execSync } = require('child_process');
try {
execSync(`wsl ${args[2]} ${args.slice(3).join(' ')}`, { encoding : 'utf-8', stdio : 'inherit' });
} catch {
// forgive me for i have sinned
}
$numOfArgs = $args.Length
for ($i=1; $i -le $numOfArgs; $i++)
{
$target = $($args[$i-1])
write-host "Trying: $($target)"
winget install $args[$i-1]
write-host "Finished trying: $($target)"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment