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

Adding nicer (shell-compatible) Path display here #98

Open
cgwalters opened this issue Feb 27, 2025 · 4 comments
Open

Adding nicer (shell-compatible) Path display here #98

cgwalters opened this issue Feb 27, 2025 · 4 comments

Comments

@cgwalters
Copy link

This is only tangentially related to this repository, but

  • The maintainers are likely to know the answer
  • It may make sense to put the code here anyways

I recently wrote this code: https://github.com/containers/bootc/blob/73de2a8ef0a312243b686c6bd2c91413ee725c05/utils/src/path.rs#L31

One of the annoying things about dealing with std::path::Path (as opposed to Utf8Path of course) is that printing them requires going via debug formatting, and it looks ugly (IMO).

The idea of that little helper struct is to print paths nicely by default where possible, but fall back to shell quoting if not.

Are you aware of something in the crates.io ecosystem for this? (I didn't see anything here but it's hard to search).

WDYT about adding this to caminio?

@cgwalters cgwalters changed the title Adding nicer Path display here Adding nicer (shell-compatible) Path display here Feb 27, 2025
@cgwalters
Copy link
Author

(Of course PathQuotedDisplay does still apply conceptually to Utf8Path as well in the case where one wants to avoid ambiguity with spaces and other unusual characters in the output like quotes etc.)

@sunshowers
Copy link
Collaborator

Thanks. I think this should not live in Camino itself — and it's quite straightforward (most of the complexity is in shell quoting which is delegated) so maybe just have it as a code snippet you can copy-paste around?

@sunshowers
Copy link
Collaborator

Though maybe this can be an optional displayer enabled by a feature on camino, hmm.

@cgwalters
Copy link
Author

Thanks. I think this should not live in Camino itself — and it's quite straightforward (most of the complexity is in shell quoting which is delegated)

Yeah, I hesitated before filing the issue here as I couldn't say it was obviously right here, but I don't think it's obviously wrong either...and I think there's maybe some argument this could reach a point where it could be in std, but we have to prove it out in crates first.

so maybe just have it as a code snippet you can copy-paste around?

Well, if it comes to that I'd probably stick it in my crate https://github.com/coreos/cap-std-ext/ which is somewhat of a grab-bag already and is already used in the places I'd want this, mostly. But, it (and cap-std) I think is less widely used than camino, which is of course way less used than std.

Though maybe this can be an optional displayer enabled by a feature on camino, hmm.

Do you mean the {:#} alternate for Display? A goal here for this is to work with Path too...I may actually try to rework this to be an extension trait.

A question for you though is: Do you see the value in this? Would you prefer it in some projects that you maintain today vs how you may print filenames currently?

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

2 participants