On 1/11/2024 1:15 PM, Jim Porter wrote: > I've been meaning to look at this in detail, but haven't had time. My > gut feeling though is that we shouldn't have a special case in this code > for when the alias starts with "cd". I'll have to do some testing with > aliases and sudo in order to have a more-helpful answer though. > > At a guess, I think a better place to add code for this is likely in > em-tramp.el. After letting this percolate in my brain for a few weeks, the answer revealed itself to me: the functions in "em-tramp.el" shouldn't throw 'eshell-external', they should throw 'eshell-replace-command'. That allows for a two-step command replacement in this case. First, 'eshell/sudo' (or 'eshell/doas') will do its replacement. Then, Eshell will evaluate that and call the inner command, which will do another replacement to expand the alias. Alfonso, does the attached patch work for you? If so, I'll merge it to master.