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

Possible to render $HOME as ~ in fd output? #1447

Open
cohml opened this issue Dec 6, 2023 · 8 comments
Open

Possible to render $HOME as ~ in fd output? #1447

cohml opened this issue Dec 6, 2023 · 8 comments
Labels

Comments

@cohml
Copy link

cohml commented Dec 6, 2023

❯ fd --version
fd 8.7.0

Say my $HOME is /Users/LongName/. If I run fd . ~, all results will have /Users/LongName/ prepended. Is it possible to have this prefix rendered as ~/?

Of course, I could do something like fd . ~ | sed 's/\/Users\/LongName/~'. But this would require fd to finish running before any substitution occurs, slowing things down massively. So I'm wondering if it is possible to have this substitution happen at the source.

If it matters, my use case is with fzf, where results start being loaded as soon as fd returns them. Hence why the slowdown of the sed approach just described would be untenable.

@cohml cohml added the question label Dec 6, 2023
@tavianator
Copy link
Collaborator

Judging by /Users, I'm guessing you're on macOS? I think it supports -u to make the output unbuffered, which may help.

Ultimately I think the best solution for this is going to be #1043.

@cohml
Copy link
Author

cohml commented Dec 6, 2023

Incidentally, and on a completely different train of thought, I stumbled upon that issue yesterday. It sounds very exciting and may indeed resolve this.

But I was dismayed by how long it seemed to have languished. Hopefully the activity will pick up on that PR and it can get merged soon. Thanks!

@cohml
Copy link
Author

cohml commented May 8, 2024

So #1043 has finally been merged, and while it does seem incredibly useful as is, it actually doesn't seem to allow for $HOME -> ~ substitution requested in this issue.

@sharkdp @tmccombs - Might this kind of substitution be possible/worth adding as an additional template string into --format? Or perhaps arbitrary substring substitution more generally?

@tavianator
Copy link
Collaborator

tavianator commented May 8, 2024

@cohml you can now do this:

tavianator@graphene $ fd --base-directory ~ --format '~/{}'
~/code
~/code/sharkdp
~/code/sharkdp/fd
~/code/sharkdp/fd/README.md
~/code/sharkdp/fd/Cross.toml
~/code/sharkdp/fd/Cargo.toml
~/code/sharkdp/fd/Cargo.lock
~/code/sharkdp/fd/CHANGELOG.md
~/code/sharkdp/fd/scripts
~/code/sharkdp/fd/scripts/version-bump.sh
...

Something more general might be useful though, it's worth making a new feature request if you have use cases that aren't covered by the existing feature.

@cohml
Copy link
Author

cohml commented May 9, 2024

@tavianator That looks perfect!

But how are you getting those colors? For me, --format seems to disable colorization entirely, even with --color="always":

image image

@tmccombs
Copy link
Collaborator

Yes, --format disables colors currently. Possibly support could be added. I'm not sure how difficult that would be. Or exactly how that would work (do we put color on the whole line, or just the path part of it?)

@tavianator
Copy link
Collaborator

@tavianator That looks perfect!

But how are you getting those colors? For me, --format seems to disable colorization entirely, even with --color="always":

Oh those colors are just GitHub syntax highlighting for ```console

@tavianator
Copy link
Collaborator

Yes, --format disables colors currently. Possibly support could be added. I'm not sure how difficult that would be. Or exactly how that would work (do we put color on the whole line, or just the path part of it?)

For bfs -printf I just color the paths

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

No branches or pull requests

3 participants