Unfortunately, there's no single answer that works 100% of the time for all environments, that I know of.
BEST - parse the full path with bash
I would recommend saving this as a shell script in a folder in your $PATH. This accepts full and relative paths, even of multiple files, then feeds it to the binary you want. In this case cmd.exe
#!/usr/bin/env bash
OIFS="$IFS"
IFS=$' \t\n'
if [[ "$@" =~ /mnt/([a-zA-Z]+)/ ]]; then
cmd.exe /c start '' "${@/$BASH_REMATCH/${BASH_REMATCH[1]}:/}"
else
cmd.exe /c start '' "$@"
fi
The section \/mnt of \/mnt\/([a-zA-Z]+)\/ in line 5 corresponds to your root. So if you have a different root, set the regular expression accordingly.
Option 2 - Create a function
As an alias, short but more unreliable.
alias cmd="cmd.exe /c start '' "${@//&/^&}""
Or
save it in one of your shell, eg: bash .bashrc .*rc files.
cmd() {
IFS=$' \t\n'
cmd.exe /c start '' "$@"
}
This works if you are invoking the file from the current shell. Thus it requires a relative path from your current directory and the escape of white spaces with a forward slash. if Your file is in the ./org folder.
eg: cmd org/Read\ me\ Official.html
To make it always relative to a particular folder, like $HOME you can append
cd $HOME && cmd.exe /c start '' "$@"
This option even accepts a program like notepad and the file with the whitespaces in the name.
eg: cmd onenote another\ file.txt
An alternative to cmd.exe /c start '' "$@" is rundll32.exe url,OpenURL '' "$@" which can have different parsing depending on your shell.
option 3 - bodge it
You can use xdg-open in combination with wsl-open a script that allows you to use Windows binaries as default and does some of the heavy weight lifting of parsing.
or use wslpath in a function to get the realpath.
cmd() {
CMD=$1
shift;
ARGS=$@
WIN_PWD=`wslpath -w "$(pwd)"`
cmd.exe /c "pushd ${WIN_PWD} && ${CMD} ${ARGS}"
}
In any case it's a pain in the ass.