Last active
December 17, 2021 05:33
-
-
Save geekobiloba/7599fa00a1bab3dbe8c12fa29c412708 to your computer and use it in GitHub Desktop.
Powershell wrapper function to make WSL commands work with Windows path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Powershell wrapper function to make WSL commands work with Windows path: | |
function WrapWSLCmd ($cmd) { | |
return { | |
$expr = 'wsl ' + $cmd | |
for ($i=0; $i -lt $args.Count ; $i++) { | |
$expr += ' ' | |
# Keep WSL command options: | |
if ( "$( $args[$i] )".StartsWith('-') ) { | |
$expr += $args[$i] | |
continue | |
} | |
$expr += '`"`$`(' + 'wslpath -a ' + "```'" + "$( $args[$i] )" + "```'" + '`)`"' | |
} | |
Invoke-Expression "$expr" | |
}.GetNewClosure() | |
} | |
# Examples: | |
# | |
# $function:vim = $(WrapWSLCmd('vim')) | |
# $function:vimdiff = $(WrapWSLCmd('vimdiff')) | |
# $function:view = $(WrapWSLCmd('view')) | |
# $function:nano = $(WrapWSLCmd('nano')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment