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

--copypairs src1 dst1 src2 dst2 src3 dst3 … and --copylist src1 src2 src3 dst1 dst2 dst3 … #73

Open
porg opened this issue Nov 9, 2022 · 9 comments
Labels
enhancement New feature or request wontfix This will not be worked on

Comments

@porg
Copy link

porg commented Nov 9, 2022

Feature Proposal

--copypairs src1 dst1 src2 dst2 src3 dst3 …

  • Copies the --copy attributes pair-wise: From src1 to dst1, then from src2 to dst2, and so on
  • If it encounters an odd number it aborts with this error: "Error: Make sure you have an even amount of arguments for --copypairs so that the --copy attributes can be copied pair wise."

--copylist src1 src2 src3 dst1 dst2 dst3 …

  • Splits the arguments list in half and copies pair wise from the first half into the latter half.
  • If it encounters an odd number it aborts with this error: "Error: Make sure you have an even amount of arguments for --copyfromto so that the --copy attributes can be copied pair wise from the first part of the list of the list to the second part of that list."

Situations of need

  • You perform some conversions from a flat source folder to a flat target folder and keep the file names.
  • You have migrated data to a medium in which the metadata was lost, and you want to restore the metadata without re-copying.

Intended use cases as a fruitful collaboration of Finder (GUI) & Terminal (CLI)

  • Drag and drop from Finder to Terminal
    • src dst files, pairwise, do as long as all pairs are in the command line, then press ENTER
    • multiple src files first, then an equal amount of same ordered multiple dst files, then press ENTER
    • one source folder and one target folder and making use of Shell globbing: --copylist /src/*.png /dst/*.webp
@porg porg changed the title --copypairs --copypairs src1 dst1 src2 dst2 src3 dst3 … and --copylist src1 src2 src3 dst1 dst2 dst3 … Nov 9, 2022
@RhetTbull RhetTbull added the enhancement New feature or request label Nov 9, 2022
@RhetTbull
Copy link
Owner

I think you could accomplish something similar with a xargs -n or a simple shell script and copyfrom in it's current form.

Not tested but something like this:

You have a list of file pairs in a file file.txt:

src1
dest1
src2
dest2
...

Then:

cat files.txt | xargs -n 2 osxmetadata --copyfrom

@porg
Copy link
Author

porg commented Nov 9, 2022

osxmeta --copypairs <drag n drop files here> ENTER is just so much more convenient.

But ok if I want drag'n'drop I could write a script only taking $0 (the whole input) which then puts each argument onto its own line, which then counts the numbers of lines:

  • if odd throw the error
  • if even runs osxmeta within a xargs clause as you propose

But yeah, until that works with my skills, again 3-4hours are gone. Shell scripting is always frustrating as soon as whitespace, special characters etc come into play.

@porg
Copy link
Author

porg commented Nov 9, 2022

And --copylist I guess can be done when the arguments passed as even-numbered to split them in two multi-line variables and iterate through them osxmeta --copyfrom $src(line $i) $dst(line $i). Or split into two files as /tmp/src.txt and /tmp/dst.txt and then merge them line alternatingly (surely a unix tool for this) and then run with your xargs.

@RhetTbull
Copy link
Owner

But yeah, until that works with my skills, again 3-4hours are gone.

But it's 10-12 hours of my time to implement and test ;-)

cat > files.txt allows you to copy and drag from Finder then press Ctrl-D when done and use that with xargs

@RhetTbull
Copy link
Owner

I've been thinking more about this and at least for now I do not intend to work on this. My rationale is this:

  1. This unnecessarily complicates the code (and subsequent maintenance) for a niche use case.
  2. I write a lot of CLI tools and try to follow the Unix ethos of "do one thing and do it well". Other tools can already be used to accomplish this. For example, the paste command can interleave the arguments from two files (as in your --copylist example) and combined with xargs can do the same as your --copypairs example. For example, this should work:

paste -d"\n" source.txt destination.txt | xargs -n 2 osxmetadata --copyfrom

If there's something that needs to be fixed in osxmetadata to work better with the standard unix command line tools, I'm happy to look at fixing it but I do not want to implement functionality already present in other command line tools unless there's a very good reason to do so.

paste example:

> cat files1.txt
File1-1.txt
File1-2.txt
File1-3.txt
> cat files2.txt
File2-1.txt
File2-2.txt
File2-3.txt
> paste -d"\n" files1.txt files2.txt
File1-1.txt
File2-1.txt
File1-2.txt
File2-2.txt
File1-3.txt
File2-3.txt

@RhetTbull
Copy link
Owner

One other option, if the source and destination files have the same name you could use osxmetadata to do a backup in the source directory, copy the .osxmetadata.json file to the destination and then do a restore.

@porg
Copy link
Author

porg commented Nov 10, 2022

After reading all your arguments I agree that this functionality shall be achieved by interplay of unix tools, and avoid osxmeta to get to big to maintain properly.

But what we very well can do is to add those use cases and solution approaches into the readme.md or the --help or manpage. So I leave this ticket open, and when I found a solution will try to create a nice writeup, which I post here in Markdown Syntax, which you can then embed into readme/manpage/--help as you see fit.

@porg
Copy link
Author

porg commented Nov 15, 2022

Thanks again for declining my request for the right reasons!

  • I further analyzed my user needs and the causes which lead to the situation.
  • From this I developed a general purpose wrapper which can fix the problem right at the beginning or in a second mode of operation also in retrospect.
  • It incorporates osxmetadata.
  • And when put into find -exec or xargs as shown by you here, it could be a true powerhorse even more (not yet tried, but it should, although I'm not sure whether my form of code and variable insertion via string passing would work with xargs or find in terms of escaping)

With great pride I present my work

  • of the last 3-4 days (21h net) — rather than 3-4h as I had optimistically estimated 😉 :
    coke — CONVERT file with any tool and KEEP parent directory, basename and filesystem metadata for output file.
  • I'd appreciate if you try it out and give me some feedback.
  • Eventually I may also think about which examples/topics/references I could possibly writeup for here in osxmetadata's README which users may come up with and need solutions for.

@RhetTbull
Copy link
Owner

Looks useful! I'll take a look when I get a chance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants