Windows/Mac Githook For python - windows

so I want to make a GitHook which removes .pyc files. So a simple shell script one line command would be find . -name "*.pyc" -delete and that's it. The problem is that some of my team members use Unix based Operating Systems where find . -name "*.pyc" -delete works fine, however some use Windows too where it doesent really work, so what can I do?

Related

using find utility to look for all .git/config files under a certain directory

I have a certain github repo that I used to test out netlify and vuepress. I somewhat lost track of where it is on the file system, so I was planning to use mdfind (I am on mac) or find to locate all the .git/config files and then grep for my github url.
But it seems surprisingly hard to convince find to look for config under the hidden .git directories.
I did find How do I search all hidden files that are in hidden folders using Terminal? and looking at it, it looks like the following would work:
find . -name '.*' \( -type d -exec find {} \; -prune -o -print \) | egrep '/.git/config'
but given that config is a highly specific file for git, I was hoping that there is a better suited find command that will do the trick. I have already given up on mdfind as it the linked question's accepted answer is skeptical about getting it to reliably find hidden files.
Note: not looking for answers based on the locate utility, or some GUI tool, this is strictly about getting find to do the work.
Use -path.
find . -path '*/.git/config'

macOS find command behaving strangely

Example of command as used in bash script:
find '/Files' -type d -name temp* -depth -delete -print
This command should delete all folders, whose names start with "temp" in '/Files' folder and its subfolders ("temp0", "temp1", "temp2" etc.).
Script is working as expected, folders are found and properly deleted.
But sometimes, for some users, on some computers etc. script is not working as expected, despite the fact that folders & files are exactly the same.
Find command fails like this:
find /Files -type d -name tempta temptal -depth -delete -print
find: temptal: unknown primary or operator
I can't find out where "tempta" and "temptal" are coming - i don't have files with that names anywhere in the folder. Temp* folders are present, but not deleted because of this error.
The only thing which might be connected, are two files named "AbcInstall.sh" and "AbcInstall.log" in "AbcTemp" subfolder. So we have "ta" and "tal" plus "Temp". These are elements which reminds on "tempta" and "temptal", but they make no real sense - it could be a coincidence.
How can "find" result resolve into something like this !?!
Sorry for the lack of better explanation - this problem is really weird. The problem is that i can't replicate this issue on my computer so all i can do is experimenting (so far without success).
Any hints or ideas are greatly appreciated.
Thx!

Delete program core file in bash script

I'm trying to delete the core file generated from when my program suddenly crashes.
For that i use this piece of code:
find . -name 'core' -delete
My question is: Is this a correct way of doing it ? Is there a better and more efficient way ?
Thanks!
If you indeed want to delete those core file, you can use:
find . -name "core*" -exec rm -f {} \;
Note: [including semicolon]
Indeed, it is hard (if not impossible at all) to come up with a "perfect solution" since the names are core files are customizable.
In linux, /proc/sys/kernel/core_pattern determines the name of core files. Therefore, you should check that to decide the pattern to be used in your "find" command.

'atal: Reference has invalid format: 'refs/Icon

I'm trying to upload a file to github and I keep getting this error when I type "git add ." or
"git commit -m 'message'" in command line (on mac os x 10.9). I am not sure what this means
'atal: Reference has invalid format: 'refs/Icon
Same problem I had with Google Drive. I simply deleted all the "Icon" files in my project folder, then, git works.
find . -name "Icon*" -type f -delete
In case you have a file named "Icon" something, use the command below will keep your own "Icon" file.
find . -type f \( -name "Icon*" ! -name "*.*" \) -delete
I had the same problem trying to push from Google Docs shared directory. When moved (and recreated) .git into local home, problem gone away.
The answer "Git fatal: Reference has invalid format: 'refs/heads/master'" mentions looking for "*conflicted*' files in .git
find .git -name '*conflicted*'
The OP confirms having done a similar operation.
The file I opened was in .git/refs/heads/ and had some weird text which didn't seem necessary
I would rather try and clone again the repo, report my modification (add, commit), and try to push again.
I downloaded a git repository from my Google Drive to a different computer and the folder icon looked as this one
And after running the following command mentioned by Yong (I've already upvoted)
find . -name "Icon*" -type f -delete
The icon of the folder became regular as follows
and problem got resolved. But this command can also delete some icons files being used on purpose so we need to get rid of the icon files being used for customising the folder/sub-folders icons. So a slightly modified command is as follows
find . -name Icon? -type f -delete
You can also change the google drive sharing option to OFF for all the folders - bit laborious but does remove the error as I just tried it.

ClearTool windows vs unix behaves different

I used ClearCase/ClearTool several years ago in an unix env.
Now I'm in a Windows env.
The following unix cleartool command will display a version tree for each unit on my_branch all at once.
For example, if I have 5 units on my_branch, 5 version trees will be displayed at the same time:
find . -version 'version (.../my_branch/LATEST)' -exec 'cleartool lsvtree -g $CLEARCASE_PN'
I'm trying to do the same in Windows, however the following command displays a single version tree. Upon closing the version tree, the next version tree will be displayed:
find . -version 'version (.../my_branch/LATEST)' -exec 'cleartool lsvtree -g %CLEARCASE_PN%'
How do I get all version trees displayed at once in Windows?
The IBM addition example page proposes (for finding version with labels for instance):
cleartool find . -type f -exec "cleartool lsvtree -a %CLEARCASE_PN%" | findstr "("
The only difference seems to be the double quotes, but it does filter through each and every versions found.
Sale for protecting elements:
cleartool find . -all -name *.bat -print -exec "cleartool protect -chmod u+x -file ""%CLEARCASE_PN%"""
However, that triggers the command for each result, which might not be what you want.
If that still doesn't work, the other approach is to use the DOS for command:
for /f %a in ('cleartool find . -version 'version (.../my_branch/LATEST)'') do cleartool lsvtree -g %a
Again, I suspect the commands would be repeated sequencially.
The only way to achieve that on Windows would be to:
put the find result in a text, making sure those versions are displayed in one line,
then using the content of that file as parameter for your Windows cleartool lsvtree -g
(since an lsvtree command can accept several pname), and see if then several graphical version tree are displayed at once.

Resources