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 new flag for printing the executed command #1042

Open
jessestricker opened this issue Jun 15, 2022 · 5 comments
Open

Add new flag for printing the executed command #1042

jessestricker opened this issue Jun 15, 2022 · 5 comments

Comments

@jessestricker
Copy link

jessestricker commented Jun 15, 2022

Proposal

Updaptes

  1. As per Implement new flag for printing the executed commands #1068 (comment),
    adding the short flag -P is no longer required. Only the long flag --print-exec may be implemented.

Original

This is essentially the same request as #943, which was closed by the original author.
Now that #406 has been implemented, this feature seems feasible again.

I propose to add a new flag -P, --print-exec, which by default will be disabled.
When enabled, it causes fd to print the full command line just before executing it.
Also, when color output is enabled at the same time, all parts in the command line which originally were placeholders will be highlighted.

This new flag adds a shortcut and formatting as a bonus for the common case of using
--exec twice to display and execute a command.
A similar convenience flag -l, --list-details already exists.

This feature request is in contrast to #1037, which proposes for only the filename to be printed.

Examples

Existing default behavior does not change:

$ fd -e rs -x rustfmt
<no output>

With -P flag enabled:

$ fd -P -e rs -x rustfmt
rustfmt ./src/lib.rs
rustfmt ./src/main.rs

Here, the ./src/###.rs part would be highlighted.

With -P flag enabled and multiple placeholders:

$ fd -P -e wav -x flac -o {.}.flac -T "TITLE=Song" {}
flac -o ./song.flac -T "TITLE=Song" ./song.wav

Here, both ./song.flac and ./song.wav would be highlighted.

@jessestricker
Copy link
Author

jessestricker commented Jun 15, 2022

Also this issue specifically does not request a fully configurable output format, for the same reason as #1037 (comment).

@ilmari-h
Copy link

Would this make for a good first issue? Having looked at the code and started part of the implementation, it seems doable for me. So fyi, I'd like to work on this.

@ilmari-h
Copy link

ilmari-h commented Jul 22, 2022

Created a draft PR #1068 for this.
At least one thing to be resolved: Should the commands be printed in the same sequence they are ran?

So for example:

$ fd -P -x echo

echo file2
file2
echo file3
file3
echo file1
file1

Or alternatively

$ fd -P -x echo

echo file1
echo file2
echo file3
file2
file3
file1

In the latter case, due to commands being executed in multiple threads, the order will not match the order of execution as it's basically random.

@tavianator
Copy link
Collaborator

Should the commands be printed in the same sequence they are ran?

I think they should be, yes

@schwa
Copy link

schwa commented Sep 22, 2022

Wonderful feature. Can't wait to see this in use.

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

4 participants