Repository navigation
Open
Labels
regressionSomething that used to work, but was broken, especially between releasesSomething that used to work, but was broken, especially between releases
Milestone
Description
If you execute a commandline -r in an abbr --function, abbr still tries to replace the abbr text at the old offset. This leads to an index out of bounds error.
Possible solutions:
- Prohibit
commandline -rinabbr --function - Read out the current command line before executing
abbr --functionand then only work with this command line. (In this caseabbrshould offer an option to replace the complete line and not just the abbreviation itself) - If the commandline changes when the
abbr --functionis executed, the replacement of the abbreviation is no longer executed
Environment:
fish --version
# fish, version 4.0.1
uname -a
# Linux XXX 5.15.167.4-microsoft-standard-WSL2 #1 SMP Tue Nov 5 00:21:55 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
echo $TERM
# xterm-256colorStart a new fish session using:
sh -c 'env HOME=$(mktemp -d) XDG_CONFIG_HOME= XDG_DATA_DIRS= RUST_BACKTRACE=full fish'Execute the following code to obtain the malfunctioning setup:
function _test
set -l current_line (commandline)
commandline -r ""
echo "test"
end
abbr -a @test --position anywhere --function _testNow that the required environment has been set up, we can execute the previously added abbr:
test @test After executing the command (press enter or space at the end), the following error is displayed:
thread 'main' panicked at src/editable_line.rs:208:29:
index out of bounds
stack backtrace:
0: 0x561531855bdc - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h1d1b4b5fa6f43fbc
1: 0x561531614423 - core::fmt::write::ha0383308c4b73ef5
2: 0x56153185736e - std::io::Write::write_fmt::h3d049babadfff437
3: 0x561531866b4f - std::panicking::default_hook::hf34f99039c48f075
4: 0x56153183b976 - fish::panic::panic_handler::{{closure}}::h345d771d51b8741b
5: 0x5615318676c8 - std::panicking::rust_panic_with_hook::h0da62165dfee2b9c
6: 0x561531856088 - std::panicking::begin_panic_handler::{{closure}}::h3aa93158d08ca3fc
7: 0x561531855fe9 - std::sys::backtrace::__rust_end_short_backtrace::h59b242cd399f0746
8: 0x5615318670bc - rust_begin_unwind
9: 0x5615315f052f - core::panicking::panic_fmt::h9f331d0a33e30d27
10: 0x5615315f03aa - core::option::expect_failed::hfd5b4101262fba60
11: 0x56153174a988 - fish::editable_line::EditableLine::push_edit::h3072887e51bc4cfc
12: 0x561531779622 - fish::reader::Reader::expand_abbreviation_at_cursor::hd6125625d3aa6bbf
13: 0x561531777721 - fish::reader::Reader::handle_execute::h7eeba566d324c4a1
14: 0x561531774565 - fish::reader::Reader::handle_readline_command::h15e5cdc6b2b644dc
15: 0x56153176fa93 - fish::reader::Reader::handle_char_event::h5c47ee2ad2b92d58
16: 0x56153176d0a8 - fish::reader::Reader::readline::h3ef3ff6e203880d5
17: 0x5615317696a5 - fish::reader::reader_read::ha19f86a9dbbf9de8
18: 0x561531606e48 - fish::throwing_main::h3a6d227385f13466
19: 0x56153183b63f - fish::panic::panic_handler::hdec78391ac6e535e
20: 0x561531600d9f - fish::main::h734af118209e6845
21: 0x56153183b453 - std::sys::backtrace::__rust_begin_short_backtrace::h49a18dfa8f7ba2bf
22: 0x56153160b380 - main
23: 0x7efc2b4301fe - __libc_start_call_main
24: 0x7efc2b4302b9 - __libc_start_main_alias_2
25: 0x5615315fe7e5 - _start
26: 0x0 - <unknown>
fish crashed, please report a bug. Debug PID 84539 or press Enter to exit
Reacted by Jacob Chapman
Metadata
Metadata
Assignees
Labels
regressionSomething that used to work, but was broken, especially between releasesSomething that used to work, but was broken, especially between releases
Activity
[-]Panic for `command -r` on using `abbr --function`[/-][+]Panic when using `command -r` in an `abbr --function`[/+]kboshold commentedon Mar 26, 2025
It is possible to workaround the issue. This solution is only possible when the
commandline -rtext is equal or longer the existing text (commandline -b).In this case you have to
echothe correct replacement to not generate a invalid output.Example
Not working (This will remove 3 characters)
Solution
faho commentedon Mar 26, 2025
(there's very likely a nicer fix than my inelegant one, but I had it ready and I believe it works so I pushed it.
not cherry-picking it to 4.0.2 in case there's something better)
editable_line: guard against empty text
faho commentedon Mar 27, 2025
Yeah, nah, that's not enough.
This can't only be triggered if the commandline is empty - even
commandline -r fcauses it as long as "f" is shorter than the abbreviation key.I think we really need to check if the ranges are in-bounds.
krobelus commentedon Mar 27, 2025
commandline -randcommandline -finside theabbr --functioncallback should probably be an error.I plan to make it silently do nothing (which is historical behavior), then I don't have to come up with an error message.
If we ever want to support this, we can implement some kind of three-way merging heuristic.
kboshold commentedon Mar 27, 2025
@krobelus but is there still a way to implement what I had above?
I would like to be able to replace the complete line without having to use regular expression.
krobelus commentedon Mar 27, 2025
you can use a binding:
bind ctrl-g,y,l _yank_lineBTW this specific one already exists, it's bound to
ctrl-x.The abbreviation framework could support something similar in future
This doesn't sound totally unreasonable.
But note that today
--functionarguments are tried one by one until one succeeds.What should we do if the first one modifies the commandline but fails? Also, should cursor movement count as modification too?
Maybe
_yank_lineoutputting nothing should be interpreted as "don't expand the abbrevation".Prevent commandline modification inside abbreviation callbacks
Prevent commandline modification inside abbreviation callbacks