nushell / nushell

A new type of shell
https://www.nushell.sh/
MIT License
32.15k stars 1.66k forks source link

Tab completion with git alias crashes nushell #11028

Open bivsk opened 11 months ago

bivsk commented 11 months ago

Describe the bug

When defining this alias: alias dots = /usr/bin/git --git-dir ($env.HOME + /.dotfiles) --work-tree $env.HOME, nushell crashes when attempting to tab-complete within the alias. I.E.: dots diff ../.conf<Tab> causes a crash.

If I define the alias as alias dots = /usr/bin/git --git-dir ~/.dotfiles --work-tree /home/four tab completion works without crashes.

How to reproduce

  1. alias dots = /usr/bin/git --git-dir ($env.HOME + /.dotfiles) --work-tree $env.HOME
  2. dots diff ../.confi<Tab> (or similar)
  3. Nushell crashes

Expected behavior

I would expect ../.conf<Tab> to be expanded to ../.config

Screenshots

No response

Configuration

key value
version 0.85.0
branch
commit_hash
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.71.1 (eb26296b5 2023-08-03) (gentoo)
cargo_version cargo 1.71.1
build_time 2023-11-08 06:41:15 -05:00
build_rust_channel release
allocator mimalloc
features dataframe, default, extra, sqlite, trash, which, zip
installed_plugins

Additional context

No response

kubouch commented 11 months ago

Backtrace (had to format manually because Nushell messes up the backtrace formatting for some reason):

The application panicked (crashed).
Message:  attempt to subtract with overflow
Location: crates/nu-cli/src/completions/command_completions.rs:98

Run with COLORBT_SHOW_HIDDEN=1 environment variable to disable frame filtering.
Run with RUST_BACKTRACE=full to include source snippets.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⋮ 8 frames hidden ⋮
9: core::panicking::panic::h65157a6ac7f1357a
  at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/core/src/panicking.rs:117
10: nu_cli::completions::command_completions::CommandCompletion::complete_commands::{{closure}}::h51e150bb8a72e320
  at /home/kubouch/git/extern/nushell/crates/nu-cli/src/completions/command_completions.rs:98
11: core::iter::adapters::map::map_fold::{{closure}}::hf91e4ce0c286c140
  at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/core/src/iter/adapters/map.rs:84
12: core::iter::traits::iterator::Iterator::fold::hcf7cc4d8553ba9c8
  at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/core/src/iter/traits/iterator.rs:2481
13: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold::h787e114ec4e903fb
  at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/core/src/iter/adapters/map.rs:124
14: core::iter::traits::iterator::Iterator::for_each::haa6ade598dd3363a
  at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/core/src/iter/traits/iterator.rs:856
15: alloc::vec::Vec<T,A>::extend_trusted::h6dc157cc05c522ef
  at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/alloc/src/vec/mod.rs:2843
16: <alloc::vec::Vec<T,A> as alloc::vec::spec_extend::SpecExtend<T,I>>::spec_extend::h6694708fc77b17a1
  at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/alloc/src/vec/spec_extend.rs:26
17: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter_nested::SpecFromIterNested<T,I>>::from_iter::h4274a8eaf4eed615
  at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/alloc/src/vec/spec_from_iter_nested.rs:62
18: alloc::vec::in_place_collect::<impl alloc::vec::spec_from_iter::SpecFromIter<T,I> for alloc::vec::Vec<T>>::from_iter::hc46194c4a2a6bba2
  at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/alloc/src/vec/in_place_collect.rs:167
19: <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter::h5b6573db7b7aefb0
  at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/alloc/src/vec/mod.rs:2711
20: core::iter::traits::iterator::Iterator::collect::h21d870e3d0792cc8
  at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/core/src/iter/traits/iterator.rs:1895
21: nu_cli::completions::command_completions::CommandCompletion::complete_commands::h13915b29f1d2bda1
  at /home/kubouch/git/extern/nushell/crates/nu-cli/src/completions/command_completions.rs:91
22: <nu_cli::completions::command_completions::CommandCompletion as nu_cli::completions::base::Completer>::fetch::hcf89dc1a01a178b0
  at /home/kubouch/git/extern/nushell/crates/nu-cli/src/completions/command_completions.rs:171
23: nu_cli::completions::completer::NuCompleter::process_completion::hcac31f0a8ac8fa9c
  at /home/kubouch/git/extern/nushell/crates/nu-cli/src/completions/completer.rs:50
24: nu_cli::completions::completer::NuCompleter::completion_helper::h29b1e23481540532
  at /home/kubouch/git/extern/nushell/crates/nu-cli/src/completions/completer.rs:329
25: <nu_cli::completions::completer::NuCompleter as reedline::completion::base::Completer>::complete::he11ef95cb287a4e7
  at /home/kubouch/git/extern/nushell/crates/nu-cli/src/completions/completer.rs:383
26: <reedline::menu::columnar_menu::ColumnarMenu as reedline::menu::Menu>::update_values::hfdcf1db2b3eec033
  at /home/kubouch/.cargo/git/checkouts/reedline-e42026a78d91c510/973dbb5/src/menu/columnar_menu.rs:544
27: reedline::menu::ReedlineMenu::update_values::h3bf5afe016ef9925
  at /home/kubouch/.cargo/git/checkouts/reedline-e42026a78d91c510/973dbb5/src/menu/mod.rs:185
28: reedline::engine::Reedline::handle_editor_event::h9efb17d2b7186433
  at /home/kubouch/.cargo/git/checkouts/reedline-e42026a78d91c510/973dbb5/src/engine.rs:948
29: reedline::engine::Reedline::handle_editor_event::h9efb17d2b7186433
  at /home/kubouch/.cargo/git/checkouts/reedline-e42026a78d91c510/973dbb5/src/engine.rs:1251
30: reedline::engine::Reedline::handle_event::hc592a0f7079d986d
  at /home/kubouch/.cargo/git/checkouts/reedline-e42026a78d91c510/973dbb5/src/engine.rs:824
31: reedline::engine::Reedline::read_line_helper::ha08b97adba57e4e5
  at /home/kubouch/.cargo/git/checkouts/reedline-e42026a78d91c510/973dbb5/src/engine.rs:801
32: reedline::engine::Reedline::read_line::h6119fb22ecb4dca9
  at /home/kubouch/.cargo/git/checkouts/reedline-e42026a78d91c510/973dbb5/src/engine.rs:631
33: nu_cli::repl::evaluate_repl::ha8efa3600e3ab6fd
  at /home/kubouch/git/extern/nushell/crates/nu-cli/src/repl.rs:448
34: nu::run::run_repl::ha89cfe7b666414dd
  at /home/kubouch/git/extern/nushell/src/run.rs:273
35: nu::main::h33255e2c541f7aa5
  at /home/kubouch/git/extern/nushell/src/main.rs:312
36: core::ops::function::FnOnce::call_once::h1a653ece34d8df75
  at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/core/src/ops/function.rs:250
fdncred commented 11 months ago

@kubouch There is a new backtrace crate in place. If you do a full backtrace you'll get code snippets that are from the backtrace.

amtoine commented 11 months ago

i think this is a duplicate of https://github.com/nushell/nushell/issues/8122. @bivsk, can you confirm?

bivsk commented 11 months ago

i think this is a duplicate of https://github.com/nushell/nushell/issues/8122. @bivsk, can you confirm?

It seems very similar. The only real difference I see is that I'm using a one-worded alias. The issue I'm facing seems to be caused by a failure to expand $env.HOME (replacing with ~/ fixes crashes).

amtoine commented 11 months ago

i think this is a duplicate of #8122. @bivsk, can you confirm?

It seems very similar. The only real difference I see is that I'm using a one-worded alias. The issue I'm facing seems to be caused by a failure to expand $env.HOME (replacing with ~/ fixes crashes).

i did add another example with alias cfg = ^git --git-dir $env.DOTFILES_GIT_DIR --work-tree $env.DOTFILES_WORKTREE in this issue a while back :wink:

amtoine commented 11 months ago

related / duplicate: #8122