You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-f works if there are other completions specified
complete -c ttt -f #doesn't prevent files from completing if it is the only command
complete -c ttt -a 'a1 a2' # after this line '-f' works
-f key works globally for the command. Not for each option (unfortunately).
Yeah, it's a bit annoying all right. :) I have a command that takes arguments from a list in a file, which complete makes very easy. But if I type one that doesn't match anything in the list, and there's a file in the current directory that what I typed completes to, it completes it as if that file were a choice in my list file. D:
@alphapapa I don't think that line is inverting the option. More likely the problem lies in that use_files gets initialized to 1 in src/complete.cpp:862:
bool use_common = 1, use_files = 1;
but since there are no matching completions, the lines with
if (o->result_mode & NO_FILES) use_files = false;
never get executed.
Question regarding the -f switch: To what is it tied? To specific (short/long) options? To command itself? To options when some conditions are fulfilled?
In code the flag controlling this seems to be tied to options - it resides in result_mode variable of the complete_entry_opt_t structure:
/// Struct describing a completion option entry.////// If option is empty, the comp field must not be empty and contains a list of arguments to the/// command.////// The type field determines how the option is to be interpreted: either empty (args_only) or/// short, single-long ("old") or double-long ("GNU"). An invariant is that the option is empty if/// and only if the type is args_only.////// If option is non-empty, it specifies a switch for the command. If \c comp is also not empty, it/// contains a list of non-switch arguments that may only follow directly after the specified/// switch.typedefstructcomplete_entry_opt_t {
// Text of the option (like 'foo').
wcstring option;
// Type of the option: args-oly, short, single_long, or double_long.complete_option_type_t type;
// Arguments to the option.
wcstring comp;
// Description of the completion.
wcstring desc;
// Condition under which to use the option.
wcstring condition;
// Must be one of the values SHARED, NO_FILES, NO_COMMON, EXCLUSIVE, and determines how// completions should be performed on the argument after the switch.int result_mode;
// Completion flags.complete_flags_t flags;
const wcstring localized_desc() const { returnC_(desc); }
size_texpected_dash_count() const {
switch (this->type) {
case option_type_args_only:
return0;
case option_type_short:
case option_type_single_long:
return1;
case option_type_double_long:
return2;
}
DIE("unreachable");
}
} complete_entry_opt_t;
...
where NO_FILES is a constant defined in complete.h:
...
/// Use all completions.
#defineSHARED0/// Do not use file completion.
#defineNO_FILES1/// Require a parameter after completion.
#defineNO_COMMON2/// Only use the argument list specifies with completion after option. This is the same as (NO_FILES/// | NO_COMMON).
#defineEXCLUSIVE3
...
Question regarding the -f switch: To what is it tied? To specific (short/long) options? To command itself?
A complete command specifies an option (--backup) and/or a set of arguments (none existing simple). When completing, we try to complete the argument if the previous parameter matches the option. We also try to complete the option itself.
If we find a matching completion of the option OR its argument, and that completion has the NO_FILES flag, then we don't do file completion for that parameter.
Wow, that was easy. Thanks @faho! Been bugging me for a long time. :)
However, I'm not sure how a command completion would request filename completion now, since there doesn't seem to be an option to complete that means "try to complete with filenames".
However, I'm not sure how a command completion would request filename completion now, since there doesn't seem to be an option to complete that means "try to complete with filenames".
I think filename is a quite common argument for cli utils, without defaulting to filename completion, some of utils don't auto-complete any more. I don't want (and I don't think it should be necessary) to write completion for each util.
@wwwjfy: Just don't use "-f". Any command that doesn't explicitly have a completion that uses "-f" (or "-x") will get files. If the completion has a "-n" condition it also has to be true to suppress files. Obviously it's possible that there might be bugs, but e.g. for the git completions it works.
Activity
maxfl commentedon Jun 13, 2012
there are two notes here:
complete -c ttt -f #doesn't prevent files from completing if it is the only command
complete -c ttt -a 'a1 a2' # after this line '-f' works
floam commentedon Aug 18, 2016
This one is quite annoying.
alphapapa commentedon Sep 21, 2016
Yeah, it's a bit annoying all right. :) I have a command that takes arguments from a list in a file, which
completemakes very easy. But if I type one that doesn't match anything in the list, and there's a file in the current directory that what I typed completes to, it completes it as if that file were a choice in my list file. D:I'm not much with C++, but what about this line:
https://github.com/fish-shell/fish-shell/blob/master/src/complete.cpp#L966
Is that inverting the option, causing it to complete files when it shouldn't?
radomirbosak commentedon Dec 28, 2016
@alphapapa I don't think that line is inverting the option. More likely the problem lies in that
use_filesgets initialized to1in src/complete.cpp:862:but since there are no matching completions, the lines with
never get executed.
Question regarding the
-fswitch: To what is it tied? To specific (short/long) options? To command itself? To options when some conditions are fulfilled?In code the flag controlling this seems to be tied to options - it resides in
result_modevariable of thecomplete_entry_opt_tstructure:where
NO_FILESis a constant defined incomplete.h:ridiculousfish commentedon Dec 29, 2016
A
completecommand specifies an option (--backup) and/or a set of arguments (none existing simple). When completing, we try to complete the argument if the previous parameter matches the option. We also try to complete the option itself.If we find a matching completion of the option OR its argument, and that completion has the
NO_FILESflag, then we don't do file completion for that parameter.faho commentedon May 5, 2017
Ummm.... this part might have something to do with it:
Don't complete files if no completion can be found
alphapapa commentedon May 5, 2017
Wow, that was easy. Thanks @faho! Been bugging me for a long time. :)
However, I'm not sure how a command completion would request filename completion now, since there doesn't seem to be an option to
completethat means "try to complete with filenames".Don't complete files if no completion can be found
faho commentedon May 21, 2017
I've now merged this fix (I love it when deleting code is all you need).
This is not in 2.6.0 since it needs a bunch of testing.
krackers commentedon Oct 16, 2017
@faho When I tried manually cherrypicking this patch into 2.6.0 I found that one issue was that
cdno longer autocompleted with the directories.faho commentedon Oct 16, 2017
@krackers: You also need to cherrypick 4afd418, since the
cd.fishcompletion script erroneously used "-f" (via "-x"). See #4061.Also, IIRC, there were a bunch more scripts that did that - at least pacman (908063d).
wwwjfy commentedon Nov 28, 2017
@faho +1 for @alphapapa 's comment
I think filename is a quite common argument for cli utils, without defaulting to filename completion, some of utils don't auto-complete any more. I don't want (and I don't think it should be necessary) to write completion for each util.
I'd certainly hope there is a workaround. Thanks!
faho commentedon Nov 28, 2017
@wwwjfy: Just don't use "-f". Any command that doesn't explicitly have a completion that uses "-f" (or "-x") will get files. If the completion has a "-n" condition it also has to be true to suppress files. Obviously it's possible that there might be bugs, but e.g. for the git completions it works.
wwwjfy commentedon Nov 28, 2017
@faho Thanks for prompt responses.
Then a few completions have issues. I met two commands with the completion issues:
patch -i <filename>pip -r <filename>They work before. I'll take a look at the completion files to see where the problem is.
faho commentedon Nov 28, 2017
Yep:
has a "-f". I'd love a PR for this that also checks the other options.
This uses the upstream completions (which just map it to bash's completions):
Also has a "-f". This one would have to be reported to the pip people (piple?).
wwwjfy commentedon Nov 29, 2017
@faho Thanks for your help. I've created a PR #4560.