Skip to content

Abbr -q return status inconsistent #8431

Closed

Description

@EmilyGraceSeville7cf

Now set --query works as defined below:

-q or --query test if the specified variable names are defined. Does not output anything, but the builtins exit status is the number of variables specified that were not defined, or 255 if more than 255 variables are not defined.

while abbr --query works contradicationary:

-q or --query Return 0 (true) if one of the WORDs is an abbreviation.

Why set --query can't behave more like abbr (check whether at least one variable is defined and return 0 in this case)? It is a breaking change of course and is not a problem when only one thing checked with set/abbr.

Activity

  1. faho commented on Nov 11, 2021

    @faho
    Member

    We should just make abbr behave like set. Either behavior is fine by itself and it's always possible to get the other by doing multiple queries, so we should change the less used tool to match the more used one.

  2. added this to the fish-future milestone on Nov 11, 2021
  3. floam commented on Nov 11, 2021

    @floam
    Member

    Nice job, you noticed a design flaw! Yeah, let's adjust abbr to do the same thing as set.

  4. faho commented on Nov 11, 2021

    @faho
    Member

    Okay, abbr returns 0 only if all given words exist. It doesn't do the counting that set does.

  5. floam commented on Nov 11, 2021

    @floam
    Member

    So it doesn't even match the docs?

  6. floam commented on Nov 11, 2021

    @floam
    Member

    I call that a free pass to make it do whatever, @faho. Want to change it up?

  7. IlanCosman commented on Nov 11, 2021

    @IlanCosman
    Contributor

    --query is generally a complete mess 😄 In all of these commands, only the first argument is true, the rest are false. But they produce a bunch of different outputs.

    function foo
        set -l var1
        set --query var1 var2 var3
        echo $status # 2
    
        functions --query foo bar baz
        echo $status # 2
        
        type --query foo bar baz
        echo $status # 0
    
        builtin --query true foo bar
        echo $status # 0
    
        command --query ls notCommand1 notCommand2
        echo $status # 0
    
        abbr abbr1 blah
        abbr --query abbr1 abbr2 abbr3
        echo $status # 1
    end
  8. faho commented on Nov 11, 2021

    @faho
    Member

    Ah, okay, there's a bug:

    # "--query": Check if abbrs exist.
    # If we don't have an argument, it's an automatic failure.
    set -q argv[1]; or return 1
    set -l escaped _fish_abbr_(string escape --style=var -- $argv)
    # We return 0 if any arg exists, whereas `set -q` returns the number of undefined arguments.
    # But we should be consistent with `type -q` and `command -q`.
    for var in $escaped
    set -q $escaped; and return 0
    end
    return 1

    That set -q $escaped should be a set -q $var.

    The comment says it's doing this style of returning to match type and command.

  9. faho commented on Nov 11, 2021

    @faho
    Member

    Okay, I made abbr do what the documentation says, and what the comments explain is to be consistent with type and command.

    That's the easier change than making it consistent with set.

  10. modified the milestones: fish-future, fish 3.4.0 on Nov 11, 2021
  11. added
    bugSomething that's not working as intended
    and removed on Nov 11, 2021
  12. changed the title [-]Inconsistency with set and abbr[/-] [+]Abbr -q return status inconsistent[/+] on Nov 11, 2021
  13. added a commit that references this issue on Dec 12, 2021
  14. locked as resolved and limited conversation to collaborators on Nov 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething that's not working as intended

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions