JamieMason / ImageOptim-CLI

Make optimisation of images part of your automated build process
https://foldleft.io/image-tools
MIT License
3.45k stars 125 forks source link

How does isaacs/node-glob handle filenames with parentheses "()"? #169

Closed anuragkothari closed 5 years ago

anuragkothari commented 5 years ago

imageoptim-cli: 2.0.3 imageOptim: 1.8.1 OS Version: macOS Mojave 10.14.1

imageoptim cli is not able handle / find file with parentheses in the name. This is very easily reproducible. I tried using both "" for the filenames as well as escaping them with back slash. The files are handled properly via the imageoptim GUI.

bash$ 
bash$ imageoptim -V
2.0.3
bash$ 
bash$ ls -1
01 filename with (Parentheses).png
02 filename without Parentheses.png
bash$ 
bash$ imageoptim "01 filename with (Parentheses).png" 
! No images matched the patterns provided
bash$ 
bash$ imageoptim 01\ filename\ with\ \(Parentheses\).png 
! No images matched the patterns provided
bash$ 
bash$ imageoptim "02 filename without Parentheses.png" 
i Running ImageOptim...
‚úì 02 filename without Parentheses.png was: 96kB now: 96kB saving: 0B (0.00%)
‚úì TOTAL was: 96kB now: 96kB saving: 0B (0.00%)
‚úì Finished
bash$ 

Not sure if I am missing something here?

JamieMason commented 5 years ago

Hi @anuragkothari, these patterns are passed directly to https://github.com/isaacs/node-glob. I'm not sure but I think it may be that they represent invalid glob patterns.

anuragkothari commented 5 years ago

Hi @JamieMason,

Thanks a lot for your response and time.

Please excuse my ignorance of git and software development in general, here are few questions I have:

  1. Does this mean it is by design?
  2. if yes then any idea how / where can I find a way to escape the the parenthesis in the filename?
  3. If no then do I have to raise an issue/bug/ticket with the https://github.com/isaacs/node-glob?

Just in case someone runs into the same issue here is a workaround (conjured and adapted from multiple google searches) I have used for the time being (involves renaming files and replacing parenthesis with some other characters which are not used in the file names and then replacing those characters back to parenthesis):

Replace "(" by "="

find . -depth -name '*(*.png' -execdir bash -c 'mv -- "$1" "${1//(/=}"' bash {} \;

Replace ")" by "#"

find . -depth -name '*)*.png' -execdir bash -c 'mv -- "$1" "${1//)/#}"' bash {} \;

Use imageoptim

find . -type f -name "*.png" -execdir imageoptim {} \;

Replace "=" by "("

find . -depth -name '*=*.png' -execdir bash -c 'mv -- "$1" "${1//=/(}"' bash {} \;

Replace "#" by ")"

find . -depth -name '*#*.png' -execdir bash -c 'mv -- "$1" "${1//#/)}"' bash {} \;

Thanks a lot for your time once again.

Regards -Anurag

JamieMason commented 5 years ago

I'm sorry @anuragkothari I honestly don't know, you would need to maybe ask the https://github.com/isaacs/node-glob project to find an answer to this.