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/environment.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/compose/environment.rs') diff --git a/src/compose/environment.rs b/src/compose/environment.rs index df83e4f..7107d57 100644 --- a/src/compose/environment.rs +++ b/src/compose/environment.rs @@ -3,6 +3,7 @@ use std::collections::HashMap; pub struct Environment { pub aliases: HashMap, pub bins: Vec, + pub cs: u8, } impl Environment { @@ -10,6 +11,7 @@ impl Environment { Environment { aliases: HashMap::new(), bins: Vec::new(), + cs: 0, } } } -- cgit v1.2.3