-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
portmaster completions spew errors if there are no matches #3949
Comments
|
@frenchie Could you please look at this? I believe you wrote the original portmaster completions. |
|
In fairness to @frenchie this probably worked fine in older versions of fish and was only broken when we made it an error if a wildcard expansion failed outside of a few contexts. |
|
The trivial fix is to move the wildcard expansion to a |
|
@krader1961 I tried that but couldn't get it to work. How about this instead? |
What exactly did you try? It should be sufficient to replace the original statement with Although, as I said earlier, this can be greatly improved given current fish capabilities. For example, it should be possible to replace the external P.S., Note that the |
|
Sorry, my previous comment was wrong. It should have said That's because sed works on lines and the original statement expects one path name per line. |
|
So, if I understand correclty, that completion wants to print directories in /usr/ports, two levels deep. I.e. the sed expressions are Removes the "/usr/ports" part. Replaces any multiple-slash runs with a single slash - which I would actually assume to be unnecessary (they can only come from the commandline token), and if the completion doesn't match the token anymore then we won't use it, which makes it actually wrong.
Picks the first two path components (after /usr/ports/, since we just removed that). So, how about this code set -l dirs /usr/ports/*/*/ # will only generate directories because of the trailing slash
string replace '/usr/ports/' '' -- $dirs? We actually don't need the token here since fish will only pick matching completions anyway. Unless the amount of completions generated here is overwhelming (e.g. it takes too long to generate them), in which case we could just generate one level deep unless a token has been given. |
|
@faho it's a little more complicated than that. The completion wants to expand to print directories in /usr/ports, up to two levels deep, but no deeper than the current commandline. So if the command line is at As you guessed, it's not ok to expand @krader1961 I'm not at my home PC right now so I can't tell you exactly what I tried. But suffice to say that several variations on "set -l foo ...; echo foo | sed ..." didn't work when used in my completion file, even though they seemed to work on the commandline. Most of the errors were something about passing the wrong number of arguments to "-a" for the complete command. Are there any differences in how fish executes code in a completion file vs interactively? Nonetheless, the code I pasted above based on __fish_complete_directories seems to work. Does that look ok to everyone? |
Ah, okay. In that case my plan B applies. Something like set -l dirs /usr/ports/(commandline -ct)*/
set dirs $dirs $dirs/*/ #expand up to the second level, but if the token already has a "/" this won't match anything. In that case it will already have happened above.
# Alternatively, we could explicitly check for a "/" in the token.
# Deeper levels will be removed by the second replace below
string replace '/usr/ports/' '' -- $dirs | string replace -r '^([^/]+/[^/]+)/.*' '$1'The regexes here are pretty much a literal translation of the sed script, minus the squashing of slash-runs.
Well, we'd usually prefer our builtin |
Don't spew warnings when there are no matches. Also, use the string builtin instead of calling sed. Fixes fish-shell#3949
Don't spew warnings when there are no matches. Also, use the string builtin instead of calling sed. Fixes fish-shell#3949
The portmaster.fish completion script includes a shell glob based on the current commandline. When there are no matches, it prints a nasty error message, like this:
It should be fixed to silently handle the case of no matches.
fish version 2.5.0, on FreeBSD 12, in QTerminal.
The text was updated successfully, but these errors were encountered: