maybe icon indicating copy to clipboard operation
maybe copied to clipboard

Be able to call Aliases as well

Open renatomefi opened this issue 9 years ago • 7 comments

While I was trying the software I immediately tried a command which is an alias in my environment, but maybe was not able to find it. Is it possible to support aliased commands?

The software is awesome, thanks!

renatomefi avatar Feb 08 '16 15:02 renatomefi

I noticed this as well, it would be handy but is it possible with the current ptrace implementation?

CBrowne avatar Feb 08 '16 16:02 CBrowne

Could you start your shell under maybe and then issue your command as usual?

daveloyall avatar Feb 08 '16 17:02 daveloyall

Thank you for bringing this up; there is actually a bit more to this issue than it may seem.

Aliases are managed by the shell, for example using bash's alias mechanism. Running an alias is therefore easily accomplished with e.g.

maybe bash -c "alias"

What you are asking for is for maybe to do this automatically.

There are two ways this could work: The first would involve maybe detecting the shell and parsing its aliases to determine which command to actually run. I don't like the sound of that as it would add a lot of complexity on top of what we are currently doing.

The other approach is maybe always invoking the shell, that is, wrapping every command with something like bash -c. This would also add some boilerplate as we cannot just use bash but have to detect the shell first, which isn't pretty either, but there is another problem: If commands are always launched using the shell, every invocation of maybe will result in the actual command being invoked as a subprocess of the shell, and python-ptrace does not support tracing subprocesses on FreeBSD and OpenBSD, so we would essentially lose support for these platforms entirely and be reduced to Linux only.

Alternative suggestions and thoughts are very welcome. It seems that sudo does the right thing, I'd be interested to know how. I just glanced through the source code but the magic puzzle piece appears to elude me.

p-e-w avatar Feb 09 '16 20:02 p-e-w

I am not sure but can we do the following:

when the call arguments[0] = locateProgram(arguments[0]) fails, we can lookup for arguments[0] in ~/.bashrc or /etc/bashrc or some similar place for it's definition or de-aliasing.

Maybe this is very distro specific.

sanketplus avatar Feb 10 '16 13:02 sanketplus

You are right @p-e-w , when I was thinking about the problem I got the idea of calling which in order to find out the alias, since the which command is implemented among all (not sure) the shells this could work. And as @sanketplus said we could do it in case the first call fails!

Other than that using bash -c should be enough! :)

Thanks for looking into this

renatomefi avatar Feb 10 '16 14:02 renatomefi

for zsh this should work isn't it?


# Enable aliases to be sudo’ed
alias sudo='sudo '
# Enable aliases to be maybe’d
alias maybe='maybe '

dimitrieh avatar Feb 18 '16 15:02 dimitrieh

Code of conduct

-----Original Message----- From: "Dimitrie Hoekstra" [email protected] Sent: ‎2/‎18/‎2016 9:16 AM To: "p-e-w/maybe" [email protected] Subject: Re: [maybe] Be able to call Aliases as well (#11)

for zsh this should work isn't it?

Enable aliases to be sudo’ed

alias sudo='sudo '

Enable aliases to be maybe’d

alias maybe='maybe ' — Reply to this email directly or view it on GitHub.

BigAlInTheHouse avatar Feb 20 '16 21:02 BigAlInTheHouse