Gitignore on executable [duplicate] - regex

This question already has answers here:
How do I add files without dots in them (all extension-less files) to the gitignore file?
(3 answers)
Closed 2 years ago.
What would be the format for excluding files that do not have an extension, such as runme, which does not have an extension. For example, if the files in my directory are:
script.sh
script.s
runme
I want to exclude the files without an extension. I suppose the regex for this would be ^[^.]+$. How does this go into a .gitignore though? What are the regex (or is it more unix/shell filepath matching patterns)?

The gitignore file format doesn't support regular expressions, just regular Unix-style patterns.
In your case, I would exclude everything and then allow the files that do have an extension. For example:
# Ignore everything
*
# Allow directories
!*/
# Allow files with an extension
!*.*
This would include files like these:
foo.txt
some/dir/bar.txt
But exclude files like these:
foo
some/dir/bar

Related

Include regexes in Sublime Text SFTP plugin

I only see "ignore_regexes" option in the Sublime SFTP config.json. Is there any way to include only certain files, for example, .h, .c and .cpp files alone from all the subfolders under the mapped folder?
Looking at the documentation for the package, the only setting that looks like it would do something like this is the ignore_regexes option that you've already found.
As such, I think the only way to do what you want would be to use a regular expression that matches everything but the files that you're interested in so that it ignores all files except the ones that you want to view.
An example of such a regular expression (which I only midly tested but seems to work) is the following (adapted from this question):
^(.(?!\.(c|h|cpp)))*$
In use, as mentioned in the documentation examples you should use \\ instead of \ in the config file since it's JSON and \ has special meaning in JSON data.

Using 'rename' command for all files in subfolders [duplicate]

This question already has answers here:
Rename files and directories recursively under ubuntu /bash
(8 answers)
Closed 5 years ago.
I am using this command to replace a word with another in many filenames (batch):
rename 's/oldname/newname/g' **
But it works for the current open folder only. I am not sure how to make it work for that directory and all the sub-directories.
Thanks.
Mike,
Try this: Create new folders, move files, delete old folder. Then, move over directories.
Regards

How to grep a directory for a string, rewrite it to something else and save in bash? [duplicate]

This question already has answers here:
How can I do a recursive find/replace of a string with awk or sed?
(37 answers)
Closed 5 years ago.
I have a bash script that does the following:
Removes a CSS directory
Copies over new SASS from source
Runs gulp task to generate CSS again
After I copy the SASS over, I would like to do the following before generating CSS again:
Find any occurrence of ('/assets and change it to ('/themes/custom/mytheme/assets in any of the files in the SASS directory.
How can I do that?
As was already mentioned, this can be done for example with a basic sed substitution. The only thing to look out for, is to escape the slashes and to use -i to edit files in place.
sed -i "s/('\/assets/('\/themes\/custom\/mytheme\/assets/" /path/to/SASS/*

File name pattern for ignore files in Mercurial

I use TortoiseHg and I have folders structure, as below:
testSet1
test1
filesystem
input_1.obj
output_1.obj
etalon_1.obj
result_1.obj
test2
filesystem
input_1.obj
output_1.obj
etalon_1.obj
result_1.obj
......
errors.txt
......
result.xml
I need to ignore only .obj files located in directories "testSetN/testN", but not in directories "testSetN/testN/filesystem".
I use glob pattern "*/*/*.obj" in .hgignore, but it doesn't work. Mercurial just ignores all .obj files in all directories (including "filesystem" directory). But if I use, for example, "testSet1/*/*.obj", then everything works fine. How can I do what I need?
It's not necessary for me to use only glob syntax. I would be grateful for any way.
Looking at https://www.selenic.com/mercurial/hgignore.5.html#syntax
Neither glob nor regexp patterns are rooted. A glob-syntax pattern of the form *.c will match a file ending in .c in any directory, and a regexp pattern of the form .c$ will do the same. To root a regexp pattern, start it with ^.
According to this, the glob */*/*.obj will match .obj files inside the filesystem directory, because the glob is not rooted. So it matches those files by rooting the glob at testSetN/
If you have the prefix of testSet on all folders, you can use the glob testSet*/*/*.obj. This way, it will ignore .obj files in a subdirectory of a directory that begins with testSet. - it would also ignore a/testSetX/testY/Z.obj as well as testSetN/testN/N.obj
Mercurial will also let you manually add files that would otherwise be ignored according to .hgignore, so you could simply ignore all .obj files, or use your original glob of */*/*.obj and hg add the files you want to track.
Edit: adding regex as discussed in the comments.
If you prefer regex, or don't have a pattern to root the glob at, you need to use a regex. The regex ^[^/]*/[^/]*/[^/]*\.obj$ to match any .obj file at exactly two levels from the repository root. That is:
^ to anchor the match at the root of the repository
[^/]*/ to match any first-level directory. That is any sequence of characters that does not contain the directory separator /
[^/]*/ again, to match any second-level directory.
[^/]*\.obj$ to match any filenames that end with .obj

How to hgignore all files of a particular extension except in one directory and its subdirectories?

I would like to use the .hgignore file of Mercurial to ignore all files with file extension .tex, except those .tex files in one particular directory and whatever subdirectory of this directory.
I presume syntax: regexp will be required for this.
A brief explanation of the particular regular expression used, would also be very welcome, so that we can all learn a bit here.
Let's say you want to exclude the directory named exclude. The following regex would then match all files that end in .tex unless exclude/ comes somewhere before that:
^(?!.*\bexclude/).*\.tex$