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

rl.expandtilde does not expand tilde #326

Closed
HeyItsJono opened this issue Jul 14, 2022 · 9 comments
Closed

rl.expandtilde does not expand tilde #326

HeyItsJono opened this issue Jul 14, 2022 · 9 comments
Labels
bug Something isn't working working as intended The usage is working as intended

Comments

@HeyItsJono
Copy link

I've been using HomeClink to approximate automatic tilde expansion and allow commands like cd ~ to cd to the user's home directory.

Unfortunately upon updating to the latest clink version, rl.expandtilde() is no longer expanding the tilde in this expression. For example, when I print the result of rl.expandtilde('cd ~'), the result is cd ~ and expanded is false. This has been happening since I upgraded from v1.3.17 to v1.3.36.

Is there any way to restore the functionality of rl.expandtilde()? I could just change the functionality of HomeClink to manually replace ~ with %HOME%, but I just wanted to make sure this wasn't a bug first.

@chrisant996
Copy link
Owner

Ugh.

The problem is that Readline's logic for expanding tilde is overly simplistic, and it wrongly expands some inputs. Fixing that has introduced the opposite problem where now it doesn't expand all tildes in an entire command line that's passed in at once.

Basically, there will need to be two different modes for the function:

  1. Expand for an entire command line. Expand the old way, which can expand multiple tildes, but doesn't respect quotes and can also incorrectly mangle certain kinds of filenames.
  2. Expand for a single filename input. Expand tilde only at beginning of the input, this guaranteeing correct treatment when the input is a single filename.

Replacing all tildes with %HOME% would create other problems. I would recommend against that!

@chrisant996
Copy link
Owner

chrisant996 commented Jul 14, 2022

As you can see in the documentation for rl.expandtilde(), the function is intended to be used with a single pathname as the input.

When used according to the documentation (such as in match generators), it is incorrect for the function to behave the way you expected it to. But the old behavior can still be useful in some special cases, so I'm adding a second argument to the function to request the old behavior.

In v1.3.37 and higher, passing true as the second argument will cause the function to treat the input as an entire command line, and behave the way it used to. Passing true in older versions is safe (and is ignored), so a script can safely use rl.expandtilde(line, true) in any version of Clink to expand the input as though it is a whole command line (except in v1.3.36).

(P.S. I am tickled that I can tag this issue with both "bug" and "working as intended" labels. 🤣)

@chrisant996 chrisant996 added bug Something isn't working working as intended The usage is working as intended labels Jul 14, 2022
@HeyItsJono
Copy link
Author

Thanks for looking into this, I'll be very glad to see this functionality returned! Definitely streamlines my shell experience.

chrisant996 added a commit that referenced this issue Jul 19, 2022
Adds an optional argument to rl.expandtilde to indicate that the input
is a whole command line, to request Readline's quirky tilde expansion to
be used and expand all tildes that are preceded immediately by a space
(or at the beginning of the input).

When the second argument is false or is omitted, then the function
behaves how it was always documented to behave (though its behavior
didn't match the documentation until v1.3.36).
@chrisant996
Copy link
Owner

This new behavior is available in v1.3.37 now.

You can update the following line in HomeClink.lua from this:

	local expanded_input, was_expanded = rl.expandtilde(escaped_input)

To this:

	local expanded_input, was_expanded = rl.expandtilde(escaped_input, true)

@HeyItsJono
Copy link
Author

That's fixed it :) Thank you for all your hard work on the project! As an aside, is there any active repo where we can submit clink completions?

@chrisant996
Copy link
Owner

is there any active repo where we can submit clink completions?

clink-gizmos could be a good place, depending on what the script is.

@HeyItsJono
Copy link
Author

is there any active repo where we can submit clink completions?

clink-gizmos could be a good place, depending on what the script is.

I was thinking specifically of CheatCompletions, but realistically it'd be ideal to have a go-to official repo for clink extensions that people could submit to via PR, in this way you don't have to comb Github via search for an extension you want, and it makes it less likely people will spend time making extensions for the same thing (for example, I think I've seen at least 4 different implementations of a git completion extension).

@chrisant996
Copy link
Owner

Well, what does it mean to have an official repo for all Clink extensions?

Should everyone load 1000 extensions if they only use 10 of them?
What about when people have different opinions about how something should work?

It's easy to make a quick and dirty hack that's good enough for my own needs, and push it into a repo where everyone else is forced to use it.
But that's optimizing for authors having minimal responsibility -- people want high quality scripts, which means any "official" repo needs to be curated, and someone has to maintain standards of quality.

That's what I'm trying to do with clink-gizmos.

What you're looking for is not a repo, really. You're looking for a catalog, where you can find things and choose whether to use them. Git repos aren't well suited to that role.

Anyway, as I've mentioned in other posts on this topic, I already invest a large amount of time into programming Clink. I'm not going to also build a catalog web site. Someone else is welcome to do so, of course.

@chrisant996
Copy link
Owner

I think I've seen at least 4 different implementations of a git completion extension).

The one in clink-completions is pretty good. Especially the PR that is pending. But Vladimir seems to have abandoned it, so I may have to promote my fork as the new active repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working working as intended The usage is working as intended
Projects
None yet
Development

No branches or pull requests

2 participants