elvish
elvish copied to clipboard
Tab completion should not expand ~ or variable
Typing echo ~/<Tab> will expand the home directory; this is not desirable.
Thank you. I considered it a bug for myself, but presumed it was intentional.
There was a recent question about this behavior on the chat channels. My reply to that question is below....
I never use Tab completion when the path includes a leading tilde so I've never been bothered by this. That's because I only do cd ~/someplace when the path is very short; e.g., cd ~ or cd ~/log. Pretty much for anything else I use location mode since I've usually already navigated to the directory and it's in my location history. Still, I agree that path completion shouldn't substitute the actual home dir for the tilde. However, I think variables should be expanded by Tab completion. If you don't want the command history to reflect the actual value at the time the command was executed then don't use Tab completion. If you do type something like cd ${A-var}/subdir followed by Tab then I would expect the variable to be expanded.
Note that expansion of a leading tilde by Tab completion is counterproductive given that user home directories almost never change. Expansion by Tab completion replaces a single character with many characters that are unlikely to change and thus has close to zero value. It is preferable to leave the expansion of the leading tilde to the code that interprets the path.
Additionally, expanding tilde makes it harder to copy-paste things from the history to documentation, for sending code to the others as example. This is more of a niche case and this functionality can be made into opt-out instead of changing the default behavior.
This is more of a niche case and this functionality can be made into opt-out instead of changing the default behavior.
While backward incompatible changes should be avoided this is one case where I think doing so is acceptable. Because (a) it only affects interactive use and thus won't break any existing Elvish code, and (b) I'm confident that most Elvish users will prefer the new, non-tilde expansion, Tab completion behavior.
It's just a small matter of someone modifying the existing code to provide the non-expansion behavior. Which is obviously not serious (i.e., sarcastic) since a change of this nature is complicated and thus not a "small matter".
From the chat server:
Hi, if I write cd /home/user/te TAB ... the input is autocompleted to cd /home/user/temp, so far so good. But, if I write cd ~/te TAB ... the "COMPLETING argument" menu is shown with only one option. > It's a bit annoying. Any way to avoid this?
xiaq replied: fix this bug, so hope remains!