Fix open windows path with spaces in prompt #8279
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This allows Windows paths to be opened using the prompt if the path has a space in it (#5921). Right now for
:cd
or:open
, if a path has spaces you must type the entire path manually between quotes. The prompt autocomplete currently puts quotes between folders or files with spaces, but it 1. is not separated properly in shellwords, 2. cannot be opened with quotes in the middle of a path, and 3. puts the separator before the closing quote which breaks the file list builder.The " characters need to be stripped out from the string if they are in the middle of the path. It is possible to use a path surrounded with doublequotes, and I originally wanted to rewrite the argument to add a " at the beginning of the argument when a file or folder with spaces is selected, but I ended up with too hacky of a solution using shellwords in the change_completion_selection function. I think if there were an ergonomic way to do this, I'd much prefer to do it that way.
I was tempted to add the bit that strips out the quotes in expand_tilde 😅. Not sure if there's a better way to do this.
The caveat with this fix is it still will not work if you start the path with " (i.e. typing :cd "C:"Program Files"" will not work). Entering :cd "C:\Program Files" does work but the autocomplete prompts will not work. I had issues maintainly compatibility with other tests and #4098 when trying to get this to work in shellwords. Maybe it could be worked around by checking if the argument starts with with " but then we run into the same issue above of determining where the argument begins.