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

Expand tilde during autocompletion #1246

Merged
merged 1 commit into from
May 21, 2023
Merged

Expand tilde during autocompletion #1246

merged 1 commit into from
May 21, 2023

Conversation

joelim-work
Copy link
Collaborator

Fixes #1175

When typing commands like :echo ~/foo.txt, the autocompletion will internally expand the tilde for matching purposes, but when the command is evaluated afterwards, the tilde is not expanded. This is very confusing for users, and raises the question of why the autocompletion respects the tilde when matching in the first place.

I can see two possible solutions:

  1. Recognise the tilde and expand it during the parsing stage
  2. Treat the tilde as a regular character during the parsing stage, but expand all arguments just before running a command

This PR uses the first approach. While I think the second approach is easier to implement, the problem is that unconditionally tilde expanding every argument after the parsing stage means that there is no way for the user to pass a literal tilde by quoting or escaping it.

@gokcehan
Copy link
Owner

@joelim-work Thanks for the patch but I'm not sure if it is a good idea to expand at the parse stage. For example, this would break tilde mappings (i.e. map ~ cd ~). Have you considered the following third option?

  1. Explicitly expand tilde during completion (e.g. :echo ~/lon<tab> would result in the text :echo /home/foo/long_name in the prompt).

This would have the advantage of only expanding at the file path context (i.e. matchFile). Passing literal tilde would still be possible by avoiding the completion mechanism. Maybe we could also consider avoiding the expansion within quotes if possible similar to how shell work. I think this approach could also be adapted for environment variables.

@joelim-work
Copy link
Collaborator Author

joelim-work commented May 14, 2023

Have you considered the following third option?

  1. Explicitly expand tilde during completion (e.g. :echo ~/lon would result in the text :echo /home/foo/long_name in the prompt).

@gokcehan Thanks, I did not realise that was a possibility at all. I think it's better than the original two approaches that I suggested, especially because there's no possibility of breaking any existing parsing rules.

I updated the PR using your suggestions. I found that both autocomplete (pressing tab) and menu complete (cmd-menu-complete and cmd-menu-complete-back) had to be fixed. Apparently avoiding the expansion with quotes already works because replaceTilde checks the raw string if the first character is a tilde, which matches ~, but not '~', "~" or \~.

@joelim-work joelim-work changed the title Expand tilde when parsing commands Expand tilde during autocompletion May 14, 2023
@gokcehan
Copy link
Owner

@joelim-work Thanks for the patch.

@gokcehan gokcehan merged commit 5b934c2 into gokcehan:master May 21, 2023
@joelim-work joelim-work deleted the parse-expand-tilde branch May 21, 2023 12:43
@gokcehan gokcehan mentioned this pull request Sep 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Shell expansions passing to commands
2 participants