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
The first two are doing the same thing, and the third can be achieved using the first two functions.
I propose to keep the first second function since it looks more sophisticated than the second first and has a better name. This may break a couple of userland functions, but that's what happens if you rely on some fish internals 😄
Ah sorry, I was meant to say keeping that one. Maybe I messed up the order.
We can also un-dunder them (removing the __ prefix)
That's certainly better! 👍 I can see they are used a lot in completions.
Also worth noting, on closer looking, __fish_is_nth_token excludes arguments (or more precisely, token starting with dash -), which looks too magic to me. __fish_is_token_n is simple and effective, so I suggest removing the former and rename the latter to fish_is_nth_token.
Also worth noting, on closer looking, __fish_is_nth_token excludes arguments (or more precisely, token starting with dash -), which looks too magic to me. __fish_is_token_n is simple and effective, so I suggest removing the former and rename the latter to fish_is_nth_token.
Please don't. It's not "magic", it's pragmatic. This is used in completion scripts, and for those options are special. Removing them is correct 99% of the time (tho it won't deal with option arguments, but that requires knowing the options beforehand - i.e. using argparse).
I'd like to pick this up. Does the "good first issue" label mean "good issue for first-time fish contributors" or "good issue for first-time open-source contributors"?
A lot of completion scripts are passing __fish_is_first_token to complete using the -n flag. In light of that, can I propose we keep __first_is_first_token and instead edit its implementation to use fish_is_nth_token?
One nice thing about internal functions is that their name doesn't matter. Case in point: it always bothered me that this was called "...token" when it is almost entirely the opposite of that. A token is the atomic, this function skips over the command and any flags or switches. Can we consider renaming it before 3.4.0 ships?
For the following example:
sudo foo --help add -f foo.fish -- foo2.fish
Technically, sudo and foo are both tokens that are ignored as commands, --help is a token that's classified as an option, -f is a token that's classified as a flag, add is a token classified as a subcommand, foo.fish is a token classified as, I don't know, argument? -- is a token that's classified as "unix commandline wizardry" and foo2.fish is another argument/payload. We only consider add, foo.fish and foo2.fish here.
What's a better name? Is "argument" generic enough? A case could be made for add to be classified as an argument further classified as a subcommand. But a case could be made that anything after sudo (or more generously, after foo) is an argument (see argc and argv). Would you consider flags and switches to be arguments? Is token the best we can do after all?
I'd think "argument" is probably the best term here, but as you pointed out, it can be misleading.
I originally suggested un-dundering this but in hindsight that seems wrong.
I think this leaky abstraction is worse than no abstraction.
The commandline builtin already offers a consistent API; users should learn that instead of an incomplete set of functions.
This way we keep fish_<Tab> more useful to the average user.
I skimmed through all functions containing "tok", "arg" or "opt", and this
is the list of command-agnostic functions:
There are several more inconsistencies; I think it's economical to clean
them up in one pass.
Once we revisit this we should probably consolidate a bunch of features in single
command (to avoid namespace pollution). Something like commandline status.
Once we revisit this we should probably consolidate a bunch of features in single
command (to avoid namespace pollution). Something like commandline status.
That would be very nice. I hope there would be a more ergonomic way to write some checks like test (count (commandline -opc)) -lt 2.
Activity
zanchey commentedon May 16, 2021
Sounds good.
krobelus commentedon May 16, 2021
__fish_is_nth_tokensounds clearer IMO.We can also un-dunder them (removing the
__prefix)kidonng commentedon May 17, 2021
Ah sorry, I was meant to say keeping that one. Maybe I messed up the order.
That's certainly better! 👍 I can see they are used a lot in completions.
Also worth noting, on closer looking,__fish_is_nth_tokenexcludes arguments (or more precisely, token starting with dash-), which looks too magic to me.__fish_is_token_nis simple and effective, so I suggest removing the former and rename the latter tofish_is_nth_token.faho commentedon May 17, 2021
Please don't. It's not "magic", it's pragmatic. This is used in completion scripts, and for those options are special. Removing them is correct 99% of the time (tho it won't deal with option arguments, but that requires knowing the options beforehand - i.e. using
argparse).kidonng commentedon May 17, 2021
You're right, I just realized options should be excluded most of time since they don't have a fixed location and count.
butterthebuddha commentedon Jun 30, 2021
I'd like to pick this up. Does the "good first issue" label mean "good issue for first-time fish contributors" or "good issue for first-time open-source contributors"?
zanchey commentedon Jun 30, 2021
Hopefully both!
butterthebuddha commentedon Jun 30, 2021
A lot of completion scripts are passing
__fish_is_first_tokentocompleteusing the-nflag. In light of that, can I propose we keep__first_is_first_tokenand instead edit its implementation to usefish_is_nth_token?zanchey commentedon Jun 30, 2021
It would be fine to do that, even as a first step to consolidate the implementation.
kidonng commentedon Jul 20, 2021
There's this
__fish_is_first_argthat does similar things, though I would argue it is useful (as it doesn't ignore options) and should be kept.Also I wonder if we can implement
__fish_not_contain_optand__fish_no_argumentswith__fish_seen_argument, in the same fashion.And there's even
__fish_first_token...kidonng commentedon Jul 25, 2021
#8096 has been merged, so I guess this can be closed.
mqudsi commentedon Feb 8, 2022
One nice thing about internal functions is that their name doesn't matter. Case in point: it always bothered me that this was called "...token" when it is almost entirely the opposite of that. A
tokenis the atomic, this function skips over the command and any flags or switches. Can we consider renaming it before 3.4.0 ships?For the following example:
Technically,
sudoandfooare both tokens that are ignored as commands,--helpis a token that's classified as an option,-fis a token that's classified as a flag,addis a token classified as a subcommand,foo.fishis a token classified as, I don't know, argument?--is a token that's classified as "unix commandline wizardry" andfoo2.fishis another argument/payload. We only consideradd,foo.fishandfoo2.fishhere.What's a better name? Is "argument" generic enough? A case could be made for
addto be classified as an argument further classified as a subcommand. But a case could be made that anything aftersudo(or more generously, afterfoo) is an argument (seeargcandargv). Would you consider flags and switches to be arguments? Is token the best we can do after all?Changelog: fish_is_nth_token + fish_nth_token
Make __fish_is_nth_token and __fish_nth_token private again
krobelus commentedon Feb 9, 2022
Thanks for bringing this up.
I'd think "argument" is probably the best term here, but as you pointed out, it can be misleading.
I originally suggested un-dundering this but in hindsight that seems wrong.
I think this leaky abstraction is worse than no abstraction.
The
commandlinebuiltin already offers a consistent API; users should learn that instead of an incomplete set of functions.This way we keep
fish_<Tab>more useful to the average user.I skimmed through all functions containing "tok", "arg" or "opt", and this
is the list of command-agnostic functions:
fish_nth_token and fish_is_nth_token are clearly the odd ones,
so I'd go back to making them internal functions only.
There are several more inconsistencies; I think it's economical to clean
them up in one pass.
Once we revisit this we should probably consolidate a bunch of features in single
command (to avoid namespace pollution). Something like
commandline status.kidonng commentedon Feb 9, 2022
That would be very nice. I hope there would be a more ergonomic way to write some checks like
test (count (commandline -opc)) -lt 2.