p-e-w / maybe

:open_file_folder: :rabbit2: :tophat: See what a program does before deciding whether you really want it to happen (NO LONGER MAINTAINED)
6.35k stars 163 forks source link

Be able to call Aliases as well #11

Open renatomefi opened 8 years ago

renatomefi commented 8 years ago

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!

CBrowne commented 8 years ago

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

daveloyall commented 8 years ago

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

p-e-w commented 8 years ago

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.

sanketplus commented 8 years ago

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.

renatomefi commented 8 years ago

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

dimitrieh commented 8 years ago

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 '
BigAlInTheHouse commented 8 years ago

Code of conduct

-----Original Message----- From: "Dimitrie Hoekstra" notifications@github.com Sent: ‎2/‎18/‎2016 9:16 AM To: "p-e-w/maybe" maybe@noreply.github.com 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.