How to ignore files with a specific extension with fast-glob? - glob

Prettier is using fast-glob to resolve glob patterns to match the files to format. I would like to include all the files in the current directory but the ones ending with either .php or .html.
I've tried several patterns but none of them is working:
**/*.[^php,html]
**/*.!{php,html}
How can I achieve this behavior?

You can use this pattern:
**/!(*.php|*.html)

Related

Gitignore generated pdf but not all pdf

In my project we have certain markdownfiles which are used to generate pdf and html with the same filename (just different extensions). I would like to gitignore those pdf files not other pdf files (which are not generated).
I know that I could manually unignore those files one by one, also I know I could designate a folder to be unignored. But I was looking for some kind of a pattern by which I could ignore the generated files, that would by itself ensure that the non-generated files are not ignored.
Generate it to specific folder/subfolder and ignore this folder by gitignore specification.
It is most simple and efective solution.
If you are opened to naming these generated pdf files with a slightly different extension such as .gen.pdf instead of .pdf, this would give you the opportunity to differentiate these files with a pattern:
*.gen.pdf
which will ignore your .gen.pdf files and not the .pdf files while keeping all your files in the same directory.
gitignore rules can't handle such a complex rule for which a file would be ignored only if another file with the same name but not the same extension exists.
If renaming your files is not an option, then you could also add an extra step in the script used to generate these .pdf files, which would simply append the name of the generated .pdf to the .gitignore.
If you have a naming convention for your files that can be used to ignore them. If the filenames does not follow a pattern, you could do it as step pointed in his answer, save the pdf files to a specific folder and just ignore that folder in your .gitignore file.

recognize bash file with no extension in phpstorm

I'm using the last version of PHPStorm, which is 7 I think and want to have file support for files using a pattern such as *.extension but those don't have an extension. I tried pattern *, which works, but puts all of my files in bash highlighting.
Does anyone have a solution for that without using the .sh extension?
Edit:
Bash file are recognize with extension .sh and .bash. It's working nicely, but what I want is to set default file type on files with no extension. If I add .* or * in the list of bash file, all my files are recognize like bash file.
Hope it's more clear, sorry for the probable mistake in my English.
It may seem weird - but you can try to actually list the files you're using explicitly reading their names.
Not sure of your use-case, but I needed it for git hooks, and there's not so much names for existing git hooks, so it's not that hard to list those :)
For the reference:
Preferences > Editor > File Types > Bourne Again Shell:

How to make hg ignore filter case insensitive

I am trying to set up an hg repo for an old project on Windows. I want to ignore images, binaries, and some 3rd party source files, however these files contains different casing for the same patterns, for example, .jpg and .JPG, abc_sth and ABC_sth.
I learned that hgignore is case sensitive, do I have to list the different cases all in the hgignore file, or are there options that I can turn on to make the ignore filter case insensitive?
Finally I get enough rep to post my own answer.
Use regex syntax, and prefix (?i). So the pattern for the example I used here can be
syntax: regexp
(?i)\.jpg
(?i)abc_

Mercurial .hgignore: Some questions on how to ignore a single file

There's a particular file in my repository, libraries/database.php, that I need ignored. However, I can't get the syntax to recognize the file - I've tried **/libraries/**/database.php and libraries/database.php in glob, and ^.libraries/database.php in regex, but neither of them work. What should I do?
After hours of following all the suggestions here and others found on the web, I found out that I was always doing it right in .hgignore, but .hgignore will not ignore files that are currently being tracked by mercurial.
You must do
hg forget mydir/myfile.ext
Or adding the file to .hgignore doesn't take affect.
syntax: glob
mydir/myfile.ext
Then the above will work.
syntax: re
^libraries/database\.php$
That will work.
But, frankly, I've always found the .hgignore syntax to be a little obscure myself. I don't really understand what glob will and won't match.
From the mercurial QuickStart guide:
"Mercurial will look for a file named .hgignore in the root of your repository which contains a set of glob patterns and regular expressions to ignore in file paths"
is your .hgignore at the right place ?
So
syntax: glob
libraries/database.php
should work.

Issue in creating Zip file using glob.glob

I am creating a Zip file from a folder (and subfolders). it works fine and creates a new .zip file also but I am having an issue while using glob.glob. It is reading all files from the desired folder (source folder) and writing to the new zip file but the problem is that it is, however, adding subdirectories, but not adding files form the subdirectories.
I am giving user an option to select the filename and path as well as filetype also (Zip or Tar). I don;t get any problem while creating .tar.gz file, but when use creates .zip file, this problem comes across.
Here is my code:
for name in (Source_Dir):
for name in glob.glob("/path/to/source/dir/*" ):
myZip.write(name, os.path.basename(name), zipfile.ZIP_DEFLATED)
myZip.close()
Also, if I use code below:
for dirpath, dirnames, filenames in os.walk(Source_Dir):
myZip.write(os.path.join(dirpath, filename) os.path.basename(filename))
myZip.close()
Now the 2nd code taks all files even if it inside the folder/ subfolders, creates a new .zip file and write to it without any directory strucure. It even does not take dir structure for main folder and simply write all files from main dir or subdir to that .zip file.
Can anyone please help me or suggest me. I would prefer glob.glob rather than the 2nd option to use.
Thanks in advance.
Regards,
Akash
Glob by design does not expand into subdirectories. It follows UNIX style path rules and expansions see the documentation for fnmatch for more information. If you want to get at the subdirectories you need to add it to the path. This example will get everything at one level down.
for name in (Source_Dir):
for name in glob.glob("/path/to/source/dir/*/*" ):
myZip.write(name, os.path.basename(name), zipfile.ZIP_DEFLATED)
myZip.close()
Doug Hellman has an excellent discussion here. If you are not using the pattern features of glob (like *.txt for all text files or *[0-9].txt for all text files that have a number before the extension) then I think your os.walk solution is better