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

Show currently processed file in -x #963

Closed
hyperknot opened this issue Feb 23, 2022 · 10 comments
Closed

Show currently processed file in -x #963

hyperknot opened this issue Feb 23, 2022 · 10 comments

Comments

@hyperknot
Copy link

hyperknot commented Feb 23, 2022

I'm running a large batch processing job using -x. It'd be nice to display the name of the currently processed file or files (with parallel processing).

I don't know any other way to achieve this. If there is a workaround please let me not.

@tmccombs
Copy link
Collaborator

Currently, the only way to do this is with something like bash -c 'echo {}; my-command {}'. However, once #960 is merged you could do it with -x echo {} \; -x my-command....

I also think this is a duplicate of #943

@hyperknot
Copy link
Author

I understand. Just a small proposal for --print-filename or similar which would print the filename without any of the complexity described above.

@tmccombs
Copy link
Collaborator

is -x echo \; that much more complicated than --print-filename?

@hyperknot
Copy link
Author

Yes, personally I'd find it more complicated. + --print-filename could use color output.

@sharkdp
Copy link
Owner

sharkdp commented Mar 4, 2022

This option seems to be requested a lot, given the amount of related discussions:

@tmccombs Multi-exec is a fantastic feature which I'm very excited about, but maybe we should reconsider adding a simple option for this? Proper formatting would be one argument. Accessibility of the feature another.

@tmccombs
Copy link
Collaborator

tmccombs commented Mar 4, 2022

Yeah, I'm persuaded by the formatting/color option.

@tmccombs tmccombs reopened this Mar 4, 2022
@vladh
Copy link

vladh commented Aug 2, 2022

I would like to second the request for this feature, with a slightly more detailed rationale.

When using the -x option, one is often dealing with a lot of files, and often performing destructive operations on those files.

In this scenario, I really do not want to add any other echo calls or any superfluous syntax to the command I am passing to -x, since I do not want to risk getting something wrong and losing data.

Having a simple flag to enable printing would make this common use-case much easier, without presenting the risk of the user accidentally getting the command wrong in the process.

I would even go as far as to say that I think this should be the default behaviour — it's important to know what commands are being run on your files.

Edit: I see this issue is being tracked more closely in #1042

@sharkdp
Copy link
Owner

sharkdp commented Sep 11, 2022

I think we can close this in favor of #1042. Let me know if anyone disagrees.

@sharkdp sharkdp closed this as completed Sep 11, 2022
@Kristinita
Copy link

Type: Reply 💬

1. Summary

is -x echo \; that much more complicated than --print-filename?

@tmccombs, -x echo \; isn’t cross-platform syntax. \; works on UNIX, ; on Windows.

2. MCVE

2.1. Online demonstration

My MCVE on CI services:

  1. Travis CI build on Ubuntu 22.04.3 LTS Jammy Jellyfish
  2. AppVeyor CI build on Windows Server 2019

2.2. Files

KiraValidFile.sh:

#!/bin/bash

KiraNonValidFile.sh:

#!/bin/Kira Goddess!

2.3. Commands

# First command
- fd --extension sh --exec echo ; --exec shellcheck

# Second command
- fd --extension sh --exec echo \; --exec shellcheck

2.4. Behavior

2.4.1. First command
  1. Ubuntu:

    $ fd --extension sh --exec echo ; --exec shellcheck
    
    ./KiraValidFile.sh
    
    ./KiraNonValidFile.sh
    
    --exec: command not found
    
    The command "fd --extension sh --exec echo ; --exec shellcheck" exited with 127.
  2. Windows:

    fd --extension sh --exec echo ; --exec shellcheck
    .\KiraValidFile.sh
    .\KiraNonValidFile.sh
    In .\KiraNonValidFile.sh line 1:
    #!/bin/Kira Goddess!
    ^-- SC1008 (error): This shebang was unrecognized. ShellCheck only supports sh/bash/dash/ksh. Add a 'shell' directive to specify.
    For more information:
      https://www.shellcheck.net/wiki/SC1008 -- This shebang was unrecognized. Sh…
    Command exited with code 

First command works for Windows, but doesn’t work for Ubuntu.

2.4.2. Second command
  1. Ubuntu:

    $ fd --extension sh --exec echo \; --exec shellcheck
    
    ./KiraValidFile.sh
    
    ./KiraNonValidFile.sh
    
    In ./KiraNonValidFile.sh line 1:
    
    #!/bin/Kira Goddess!
    
    ^-- SC1008: This shebang was unrecognized. ShellCheck only supports sh/bash/dash/ksh. Add a 'shell' directive to specify.
    
    For more information:
    
      https://www.shellcheck.net/wiki/SC1008 -- This shebang was unrecognized. Sh…
    
    The command "fd --extension sh --exec echo \; --exec shellcheck" exited with 1.
  2. Windows:

    fd --extension sh --exec echo \; --exec shellcheck
    \; --exec shellcheck .\KiraValidFile.sh
    \; --exec shellcheck .\KiraNonValidFile.sh

Second command works for Ubuntu, but doesn’t work for Windows.

3. About cross-platform syntax

When I read this issue tracker, it seems to me that in most discussions here users and developers discussing the behavior of fd in UNIX shells without considering the Windows command prompt syntax. Users who want cross-platform syntax support may be in the minority here, but we exist. I would like fd to have more cross-platform syntax so that users don’t have to write different commands for different operating systems. Especially for such frequently needed tasks as printing filename.

Thanks.

@Kristinita
Copy link

Type: Reply 💬

I think we can close this in favor of #1042. Let me know if anyone disagrees.

@sharkdp, #1042 and #1068 about printing the executed commands, this issue about printing the filenames. I would prefer fd to print filenames rather than the same executed command for all files. If fd had a CLI argument for printing filenames, maybe users won’t be upset.

Thanks.

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

5 participants