Skip to content

cannot alias to the same command anymore  #8246

Description

@MangoIV

Note
There is an easy workaround, namely using old-alias instead of alias

Describe the bug

since #8123 we cannot alias a command to the same name anymore; I think this is a common use-case so I thought I'd file it as a bug.

How to reproduce

try to create alias nix = nix -Lv

Expected behavior

every time I call nix, this gets substituted by nix -Lv

Configuration

key value
version 0.76.1
branch
commit_hash
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.67.0 (fc594f156 2023-01-24) (built from a source tarball)
cargo_version cargo 1.67.0
pkg_version 0.76.1
build_time 1980-01-01 00:00:00 +00:00
build_rust_channel release
features default, zip
installed_plugins

Activity

  1. added
    category:inconsistent-behavior
    on Feb 27, 2023
  2. fdncred commented on Feb 27, 2023

    @fdncred
    Contributor

    As a work-around, does it help to create a custom command?

    def nix [] { nix -Lv }
    
  3. MangoIV commented on Feb 27, 2023

    @MangoIV
    ContributorAuthor

    no, it tells me "unknown flags -Lv"

  4. fdncred commented on Feb 27, 2023

    @fdncred
    Contributor

    oh, it's redefining the same name. You might be able to get away with changing nix -Lv to ^$"nix -Lv" or ^$"(nix -Lv)" but I'm not sure.

  5. MangoIV commented on Feb 27, 2023

    @MangoIV
    ContributorAuthor

    btw; the error message is also (slightly) misleading:

    Alias does not point to internal call

    At least for me it wasn't immediately obvious before reading the actual code that this means that I used the same name twice...

    (I don't think you should change the error message if this behavior will get fixed anyway but perhaps if it doesn't, this should be changed...)

  6. amtoine commented on Feb 27, 2023

    @amtoine
    Member

    i have the same issue and used to define cp, rm and mv to their --verbose versions 😢
    would love to see that back 😋

  7. fdncred commented on Feb 27, 2023

    @fdncred
    Contributor

    I kind of wonder what would happen if we had a run_internal command and then did something like

    def cp [...args] {
      run_internal cp --verbose $args
    }
    

    It may not work either because I can't even get this to work

    def cp [...args] {
      do { cp -v $args }
    }
    
  8. amtoine commented on Feb 27, 2023

    @amtoine
    Member

    I kind of wonder what would happen if we had a run_internal command and then did something like

    mm why not 🤔

    but the former alias cmd = cmd --some-option-you-want-as-the-default looks really clear and neat to me 😮

  9. MangoIV commented on Feb 27, 2023

    @MangoIV
    ContributorAuthor

    I think it's kinda obvious that this should be possible. For now we can use old_alias though.

  10. amtoine commented on Feb 27, 2023

    @amtoine
    Member

    For now we can use old_alias though.

    oh wow, how did you find that? 😮

  11. MangoIV commented on Feb 27, 2023

    @MangoIV
    ContributorAuthor

    See the mentioned PR :3

  12. added
    A:alias
    on Feb 27, 2023
  13. amtoine commented on Feb 28, 2023

    @amtoine
    Member

    See the mentioned PR :3

    jeez i searched old_alias...
    really did not want to read anything yesterday, terrific 😆

    thanks 👍

  14. bobhy commented on Mar 1, 2023

    @bobhy
    Contributor

    It would be nice if the same extension syntax worked for external as well as internal commands, so, for example, I could do this:

    alias ls = SomeMagic(ls -a)
    alias grep = SomeMagic(grep -i)

    It has always bugged me that (most) shells allow the old_alias syntax: how do they know to stop recursion? Putting some explicit syntax in the expansion would be a good thing, I think.

    I do think we need some solution here, otherwise Nushell will never be able to deprecate old-alias.

  15. added a commit that references this issue on Mar 12, 2023
  16. added this to the v0.77.0 milestone on Mar 13, 2023
  17. Miuler commented on Mar 15, 2023

    @Miuler

    My script in nushell has a error:

    Error: nu::parser::unknown_state
    
      × Unknown state.
        ╭─[zoxide.nu:32:1]
     32 │   }
     33 │   cd $path
        ·   ─┬
        ·    ╰── Alias does not point to internal call.
     34 │ }
        ╰────

    This error is in follow functions:

    # Jump to a directory using only keywords.
    def-env __zoxide_z [...rest:string] {
      # `z -` does not work yet, see https://github.com/nushell/nushell/issues/4769
      let arg0 = ($rest | append '~').0
      let path = if (($rest | length) <= 1) and ($arg0 == '-' or ($arg0 | path expand | path type) == dir) {
        $arg0
      } else {
        (zoxide query --exclude $env.PWD -- $rest | str trim -r -c "\n")
      }
      cd $path
      #^^^^^^^
    }
    
    # Jump to a directory using interactive search.
    def-env __zoxide_zi  [...rest:string] {
      cd $'(zoxide query -i -- $rest | str trim -r -c "\n")'
      #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    }
    
    ...
    
    alias cd = __zoxide_z
    alias cdi = __zoxide_zi
    
    nu version:      v0.77.0
    zoxide version:  v0.9.0
    

    ajeetdsouza/zoxide#542

  18. fdncred commented on Mar 15, 2023

    @fdncred
    Contributor
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

    A:aliascategory:inconsistent-behavior

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions