From 8a7af4aacc0d67a9887ca1fd665b1694fd62a8ca Mon Sep 17 00:00:00 2001 From: Rory Dudley Date: Mon, 20 May 2024 11:27:45 -0600 Subject: Allow aliases with the same name as their verb Previously, when trying to add an alias that used the same name as its command, an infinite recursion loop would occur, and the program would panic after the call stack got too deep. For instance, something like: alias grep='grep --color=always' would cause it to panic. This patch adds a new field to the Environment struct called 'cs' (for call stack), which can be used to keep track of how many levels deep into the Poem::read() function we are in. At the moment, it only allows going two levels deep, but since it's just a u8 value, this could be increased in the future. The above example now works correctly, but it does mean that aliases within aliases are not possible, currently. --- src/compose.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/compose.rs') diff --git a/src/compose.rs b/src/compose.rs index 46f04a7..dfbbaef 100644 --- a/src/compose.rs +++ b/src/compose.rs @@ -53,7 +53,7 @@ fn rrr(path: PathBuf, env: &mut Environment) { } }; - let poem = match Poem::read(poetry, &Environment::new()) { + let poem = match Poem::read(poetry, &mut Environment::new()) { Ok(poem) => poem, Err(e) => { eprintln!( -- cgit v1.2.3