Skip to content

which shows aliases as built-in commands #8577

Closed

Description

@rgwood

Describe the bug

which incorrectly describes aliases as "Nushell built-in commands". I think it probably needs to be updated after @kubouch's recent alias changes.

How to reproduce

> alias foo = print "foo!"
> foo
foo!
> which foo
╭───┬─────┬──────────────────────────┬──────────╮
│ # │ arg │           path           │ built-in │
├───┼─────┼──────────────────────────┼──────────┤
│ 0 │ foo │ Nushell built-in command │ true     │
╰───┴─────┴──────────────────────────┴──────────╯

Expected behavior

I expect which to describe foo as an alias, and for the built-in column to be false.

Screenshots

No response

Configuration

key value
version 0.77.2
branch main
commit_hash 66ad83c
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.66.1 (90743e729 2023-01-10)
rust_channel 1.66.1-x86_64-unknown-linux-gnu
cargo_version cargo 1.66.1 (ad779e08b 2023-01-10)
build_time 2023-03-22 18:59:19 -07:00
build_rust_channel debug
features default, zip
installed_plugins inc

Additional context

No response

Activity

  1. added
    A:alias
    on Mar 23, 2023
  2. kubouch commented on Mar 23, 2023

    @kubouch
    Contributor

    That's because alias is a type of a command now. For someone attempting to look at it, the way to query aliases now is to query commands, then check is_alias() defined by the Command trait. A lot of the implementation details in the code referring to aliases, like find_alias(), refer to the old alias implementation and will be removed eventually.

  3. a13h commented on Mar 23, 2023

    @a13h
    Contributor

    I am happy to try working on this!

    Is @kubouch's change in question part of this PR: #8557

    It would be my first contribution to nushell so I'm in the process of setting up my dev environment and can start exploring the code now! I've gone through the Review Process section of CONTRIBUTING.md but please let me know if I'm missing a step wrt assigning this to myself.

  4. kubouch commented on Mar 23, 2023

    @kubouch
    Contributor

    @AyushSingh13 Great, it's yours! You can just start exploring and even if you're not ready and have some questions you can open a draft PR, it's easier to discuss over code.

  5. a13h commented on Mar 24, 2023

    @a13h
    Contributor

    @kubouch - awesome, thank you! Will come back with loads of questions this weekend I'm sure :)

  6. a13h commented on Mar 28, 2023

    @a13h
  7. rgwood commented on Mar 28, 2023

    @rgwood
    ContributorAuthor

    ^that doesn't seem related to this issue. You will likely have better luck filing a new issue or asking on Discord.

  8. a13h commented on Mar 28, 2023

    @a13h
    Contributor

    thank you - will create a new issue/ask on Discord! I have hidden the comment so it doesn't pollute this thread and will come back with specifics about this issue ASAP

  9. jooooscha commented on Mar 29, 2023

    @jooooscha

    Just to add my three cents: The which command in bash shows the definition of the alias. This is useful when you forget what exactly the alias does.

    For example, for alias hi=echo "hi", calling which hi would reveal the definition echo "hi".

    I think this is an important feature, and the nushell which command should show that, too.

  10. a13h commented on Mar 31, 2023

    @a13h
    Contributor

    @jooooscha - I think that's a great idea - I have started to explore the code so will report back on what changes are required for this :)

    PS: for anyone that's interested, I fixed my tmux issue on both laptops by doing a tmux kill-server. I'm still not sure what the root cause was but the server seemed to have gone into some bad state and I haven't been able to reproduce it/link it explicitly back to nushell.

    Either way, will continue on with this issue finally! Apologies for the delay!

  11. a13h commented on Apr 6, 2023

    @a13h
    Contributor

    Update: I've spent some time exploring the code and I'm being a Rust ecosystem + language newbie at the same time so thank you for bearing with me.

    I understand that crates/nu-command/src/system/which_.rs has a which_single function which eventually leads down to a get_entry_in_commands function which is responsible for returning Nushell built-in command/Nushell custom command.

    For some reason the call to check if something is a custom_command (engine_state.get_decl(decl_id).is_custom_command()) returns false. I also checked that engine_state.aliases is an empty vector even though I have defined alias ll = ls -al as my test alias.

    So far I'm doing some newbie println! debugging but going to try and understand LLDB to see if I can do some more sophisticated debugging to understand the code path for adding an alias and then fetching an existing alias a bit better. Any advice on levelling up on the Rust side quicker is appreciated ofc :)

  12. kubouch commented on Apr 6, 2023

    @kubouch
    Contributor

    engine_state.aliases is still the old alias implementation that will be deleted. Actually, most of the stuff referring to aliases in the engine is the old implementation and will be deleted. The current aliases are implemented as decls, but they should return true when you call is_alias() on them.

    Inside which_.rs there is get_entry_in_aliases() which again refers to the old alias implementation and will be deleted. The correct way to query aliases would probably be to use the get_entry_in_commands() and then add another if-else branch there checking for is_alias().

  13. a13h commented on Jul 1, 2023

    @a13h
    Contributor

    Thank you for your guidance and apologies for completely dropping the ball on this for so long! I have created this super simple draft PR here: #9580 (review)

    Just checking how the tests work and will hopefully be ready for review soon - thank you again for your patience!

    Once this is done, I can an issue for implementing @jooooscha's idea of displaying alias definitions in which too.

  14. added a commit that references this issue on Jul 8, 2023
    ad125ab
  15. added this to the v0.83.0 milestone on Jul 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A:aliasgood first issue

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions