Skip to content

Instantly share code, notes, and snippets.

@geekobiloba
Last active December 17, 2021 05:33
Show Gist options
  • Save geekobiloba/7599fa00a1bab3dbe8c12fa29c412708 to your computer and use it in GitHub Desktop.
Save geekobiloba/7599fa00a1bab3dbe8c12fa29c412708 to your computer and use it in GitHub Desktop.
Powershell wrapper function to make WSL commands work with Windows path
# 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