Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use aliases command in entr #50

Closed
nicola-lunghi opened this issue Sep 20, 2020 · 6 comments
Closed

use aliases command in entr #50

nicola-lunghi opened this issue Sep 20, 2020 · 6 comments

Comments

@nicola-lunghi
Copy link

Hi
I have an alias set like
alias my_cmd='./do_something && ./do_something_else && echo "done"'

how can I use it with entr like

git ls-files | entr my_cmd

??

@iamleot
Copy link
Contributor

iamleot commented Sep 20, 2020

Hello @nicola-lunghi!
Probably the easiest way is just using a script instead of having an alias.

@nicola-lunghi
Copy link
Author

nicola-lunghi commented Sep 20, 2020

Hi I just found that I can do

git ls-files | entr sh -c "${BASH_ALIASES[my_cmd]}"

In bash > 4.0

:-)

@eradman
Copy link
Owner

eradman commented Sep 21, 2020

I agree with @iamleot that a script it usually the most strait-forward thing to do:

git ls-files | entr ./build.sh

This is worth it even for a one-line script because when you cd to the directory it's obvious what to do. Thanks for posting your solution as well! Closing

@eradman eradman closed this as completed Sep 21, 2020
@nielsbom
Copy link

I use quite a lot of aliases, having entr be able to use them directly would be very comfortable.

I don't know how to write C, but I'm interested to know how/why this was not implemented. Are aliases special or difficult in some ways?

Could I write a PR to enable this functionality? Would you accept such a PR @eradman ?

@eradman
Copy link
Owner

eradman commented Sep 24, 2021

Aliases are special because they're not part of the environment, they're a feature of the shell. This means entr can't inherit or inject them.

@nielsbom it's good that you brought this back up because there is a simple we can do, namely run shell with the login -l flag:

... | entr sh -l -c "..."

Each shell is different, but here is the relevant part from the bash(1) man page

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.

Another option is to source a file that defines aliases directly

... | entr sh -c ". ./profile; ..."

@eradman eradman reopened this Sep 24, 2021
@eradman
Copy link
Owner

eradman commented May 4, 2022

Closing since the use of shell aliases it outside the scope of what entr should or can take responsibility for.

As noted, files can be sourced manually

... | entr -s '. .myenv.sh; ...'

@eradman eradman closed this as completed May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants