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

Add default flags for programs used with exec #1427

Open
cohml opened this issue Nov 16, 2023 · 2 comments
Open

Add default flags for programs used with exec #1427

cohml opened this issue Nov 16, 2023 · 2 comments

Comments

@cohml
Copy link

cohml commented Nov 16, 2023

Very very often I use fd to grep inside many files at once. For example:

fd . -e py -X grep foo

However, the results come back without color, which can be hard to parse. So I must always manually specify --color=always:

fd . -e py -X grep --color=always foo

This left me wondering if it were somehow possible to, without relying on global aliases, configure things such that when I pass command X into exec/exec-batch, default flags appropriate for X would also be automatically supplied.

For example, perhaps some fdexec.rc/fdx.rc file with contents like

du="-h"
grep="--color=always --line-number"
rm="-i"

Let me know you think about this proposal, or if the desired behavior is already possible, please let me know how. Thanks!

@tmccombs
Copy link
Collaborator

tmccombs commented Jan 8, 2024

A possible work around for this:

Create a wrapper script that looks like

com="$1"
shift

case "$com" in 
  du) du -h "$@";;
  grep) grep --color=always --line-number "$@";;
  rm) rm -i "$@"
esac

then you can use fd . -e py -X invoke grep foo

where invoke is the name of your script.

@cohml
Copy link
Author

cohml commented Jan 8, 2024

Hey that's pretty slick, thanks @tmccombs!

Not as simple or elegant IMHO as supporting this feature natively from within fd as I initially described. But in the meantime, your proposal is a very nice stopgap solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants