Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Git+Bash / GitBash: Add files matching both first-letter-uppercase or all-lowercase filenames of certain pattern along with respective plurals

I have some Laravel/Livewire files matching filename patterns like seen in below:

app/Livewire/String1Table.php
app/Livewire/String1s.php
app/Livewire/EditString1.php

app/Models/String2Table.php
app/Models/SubDir/SomeString2.php

resources/views/livewire/string1-table.blade.php
resources/views/livewire/string1s.blade.php
resources/views/livewire/edit-string1.blade.php

Now I want to git add only those files that contain String1 or string1 (apparently disregarding the case) and only those that are within the [L|l]ivewire folder (disregarding the case here too).

I know that git add supports the asterisk and some of regex, but does it support all the bash related pattern matches ? Any ideas on how can I achieve what I want? Hope the requirement is clear.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

From the first 2 informative comments, I am wondering if this would be correct: git add *[Ll]ivewire/*String1[?s] ? I am not so well-versed with regex that much, that’s why I wanna know if anyone can come up with a way or partial way. I don’t wanna end up adding files incorrectly.

>Solution :

You can use find to locate the desired files:

$ find . -path '*/[Ll]ivewire/*' -name '*[Ss]tring1*'
./app/Livewire/String1s.php
./app/Livewire/EditString1.php
./app/Livewire/String1Table.php
./resources/views/livewire/string1-table.blade.php
./resources/views/livewire/edit-string1.blade.php
./resources/views/livewire/string1s.blade.php

Once you have a find command that matches the desired files, you can run git add on each file by passing an -exec option:

$ find . -path '*/[Ll]ivewire/*' -name '*[Ss]tring1*' -exec git add '{}' +
$ git status -s
A  app/Livewire/EditString1.php
A  app/Livewire/String1Table.php
A  app/Livewire/String1s.php
A  resources/views/livewire/edit-string1.blade.php
A  resources/views/livewire/string1-table.blade.php
A  resources/views/livewire/string1s.blade.php
?? app/Models/
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading