Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong order of parameter expansion #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion wsl_nvim.bat
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,15 @@ set pp=%pp:;=\;%
:: full wt.exe path: %LOCALAPPDATA%\Microsoft\WindowsApps\wt.exe
:: GIANT GOTCHA! Can only strip outter double quotes from %pp% if placing within
:: double quotes, else special chars will be interpretted literally, e.g. ^ will escape.
set launch="p=$(wslpath '%pp:"=%') && cd \\"^""$(dirname \\"^""$p\\"^"")\\"^"" && %my_app% \\"^""$p\\"^""
:: Another GOTCHA! regarding the order of parameter expansion / sub-shell execution:
:: To use parameter expansion for the $p variable, the $ must be escaped using a backslash \$
:: because the command is passed to bash via -c and hence would otherwise perform the expansion too early
:: in the context of the shell that is executing the "bash -c" command instead of passing it through
:: to the actual sub-shell. This resulted in $p being empty as it is only defined *inside* the sub-shell.
:: This is also true for the $(dirname "\$p") sub-shell call which must be escaped as \$() to avoid it being
:: executed before its argument "\$p" got expanded which would result in it outputting a dot, because it
:: would consume the literal string "\$p" as an argument, which is not a path.
set launch="p=$(wslpath '%pp:"=%') && cd \\"^""\$(dirname \\"^""\$p\\"^"")\\"^"" && %my_app% \\"^""\$p\\"^""

:: Use `start` to launch cmd and cleanup/close the parent process immediately.
:: bash -i starts bash interactively.
Expand Down