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

Consider removing '?' wildcard #4520

Closed
PenegalECI opened this Issue Nov 3, 2017 · 9 comments

Comments

Projects
None yet
5 participants
@PenegalECI
Copy link
Contributor

PenegalECI commented Nov 3, 2017

Hello, there.

Using fish 2.4.0 as packaged by Debian Stretch, I noticed that zpool's -? makes fish prompt an error message:

root@Alioth ~ {⌗0/⬓54}[1]꩜# zpool -?
No matches for wildcard '-?'.  (Tip: empty matches are allowed in 'set', 'count', 'for'.)
fish: zpool -?
            ^

It looks like fish tries to interpret the interrogation mark, whereas it's a legitimate switch of zpool:

zpool -?                    
                            
    Displays a help message.

Such a bug seems beyond my development knowledge, so I opened this issue.

root@Alioth ~ {⌗0/⬓54}[0]꩜# fish --version
fish, version 2.4.0
root@Alioth ~ {⌗0/⬓54}[0]꩜# uname -a
Linux Alioth 4.9.0-4-amd64 #1 SMP Debian 4.9.51-1 (2017-09-28) x86_64 GNU/Linux
root@Alioth ~ {⌗0/⬓54}[0]꩜# echo $TERM
screen

FWIW, fish executes in a tmux session, though I don't think it matters. If you need more data, feel free to ask it.

Regards.

@faho

This comment has been minimized.

Copy link
Member

faho commented Nov 3, 2017

Such a bug seems beyond my development knowledge, so I opened this issue.

Unfortunately, it's not a bug. The ? is the single-character wildcard, so this tries to match files in your current directory that are called -a or -b or such.

You'll need to quote it if you wish to use it - zpool '-?' or zpool -\? or similar.

Note that it's a wildcard character in bash as well, but bash's default behavior is to pass the literal glob if no file matches. E.g. try this in bash, then touch ./-a and try again.

See #3649, where we've discussed dropping this wildcard. We came to the conclusion that it wasn't worth it for fish 2.X, but we've since started preparing an incompatible 3.0, so we might want to reconsider.

@faho faho changed the title zpool's "-?" switch displays a fish error Reconsider removing '?' wildcard Nov 23, 2017

@faho faho added this to the fish-3.0 milestone Nov 23, 2017

@mqudsi

This comment has been minimized.

Copy link
Contributor

mqudsi commented Nov 30, 2017

Can we close either this or #3649 in favor of the other? It seems there is consensus on the inutility of ? in general.

@faho

This comment has been minimized.

Copy link
Member

faho commented Nov 30, 2017

#3649 was closed after the documentation was improved because we didn't want to break compatibility. This is a re-run because we've decided to break compatibility for 3.0.

@cben

This comment has been minimized.

Copy link
Contributor

cben commented Dec 17, 2017

+0.5, I also never want ? as wildcard and frequently want it literal.
Literal use cases from my history | grep '\?' (total 355 commands):

  • pasting URLs containing ?foo=bar param to curl and other commands — URLs are mostly shell-friendly and usually woulndn't need quoting, except for ? and & chars. (187 commands; only 44 of these contain an &, so other ~140 could avoid quoting)
  • regexps using ?, in grep / ag / sed commands (137 commands, though being regexps majority of them would need quoting anyway).
  • perl / ruby / jq one-liners (28 commands)
  • the rest are english strings in args / comments / accidental pastes to terminal :)

Only 3 wildcard uses in about 5 commands from 355:

  • file --dereference /usr/bin/python?.? (could use python*.* just as well)
  • ls ~/miq/??, ls ~/miq/?? -d, rm ~/miq/?? -rf — don't remember what these 2-letter files/dirs were, but here I definetely relied on matching exactly 2 letters.
  • rm fedora.sh?* -i — I guess this was to remove .sh~, .sh.orig etc. but not .sh, so relied on ?* matching at least one letter.

=> I must admit this is not the overwhelming evidence I expected :) It does confirm I don't need ? wildcard, but shows only mild reduction in need for quoting — both URLs and regexes have other special chars...
Sounds like main benefit is simpler syntax / less cognitive load?
Main price is incompatibility to older fish and yet another POSIX incompatibility. I don't know if worth it, but HTH reach a decision :)

P.S. For the quoting use cases, I feel what I really want is not syntax but interactive convenience.
It's nice to be able to leave some stuff unquoted, but that's hit-and-miss — as I keep editing the command may need to add quoting later anyway. What I'd love is a convenient key to quote an arg I'm typing / just pasted after the fact, without manually traveling back with cursor.

@cben

This comment has been minimized.

Copy link
Contributor

cben commented Dec 17, 2017

ref #839 #3681 which conversely asked for richer wildcards.

@mqudsi mqudsi changed the title Reconsider removing '?' wildcard Consider removing '?' wildcard Feb 3, 2018

@d2xdt2

This comment has been minimized.

Copy link

d2xdt2 commented Feb 19, 2018

? is highly useful for the rename command.

Given the files foo1, ..., foo9, foo10, ..., foo278, the commands

rename foo foo0 foo?
rename foo foo0 foo??

will turn them into foo001, ..., foo009, foo010, ..., foo278.

For the zpool -? case, this will get changes to -h or --help for sure if Oracle makes ZFS GPLv2. Until then using -? will probably been seen by many as not following in the GNU standard for arguments.

@mqudsi

This comment has been minimized.

Copy link
Contributor

mqudsi commented Feb 20, 2018

@Dtxdt2 per the Linux rename(1) man page, this functionality is baked into rename and does not need shell support. Many commands natively support globbing which is overridden when the shell performs its own.

Ref https://linux.die.net/man/1/rename

Also please keep in mind that fish isn’t Linux-only, and people have been using native ZFS with fish for years under generous, permissive licenses like the BSD.

@faho

This comment has been minimized.

Copy link
Member

faho commented Feb 21, 2018

this functionality is baked into rename and does not need shell support.

Unfortunately that's not correct. The man page is simply assuming that your shell will do that.

Try rename foo foo0 'foo??'. It'll tell you that the file can't be found.

Though note that there's a number of rename implementations. Mine's the one from util-linux, which is the successor of the one that man page is from.

The question here is if * could be used here instead. And most likely it could. It probably wouldn't result in any false-positives, and ? has risk of false-positives as well. If any file is named fooA, you might not want to renumber that. So instead you should actually match files with numbers that don't start with 0. In which case you either need a more complicated glob than fish can currently do, or you need to use something like find. Or you need to glob and then string match to filter further.

@mqudsi

This comment has been minimized.

Copy link
Contributor

mqudsi commented Apr 1, 2018

I’ve been putting this one off because I didn’t want to get my head chewed off for breaking someone’s script, though secretly dying to see it done. Thank you @ridiculousfish

ridiculousfish added a commit to ridiculousfish/fish-shell that referenced this issue May 6, 2018

Feature flag support for ? wildcard
This partially reverts 6e56637 and fish-shell#4520
by bringing back the ? wildcard, guarded by the qmark-noglob feature flag.

ridiculousfish added a commit to ridiculousfish/fish-shell that referenced this issue May 6, 2018

Feature flag support for ? wildcard
This partially reverts 6e56637 and fish-shell#4520
by bringing back the ? wildcard, guarded by the qmark-noglob feature flag.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment