Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I automate file extension change for Matlab files pushed to GitHub?

Tags:

git

github

matlab

I've started using Github for hosting much of my code, including my Matlab code. It turns out that Github syntax highlights code based on its extension rather than the content of the file. This is not so great for Matlab m files. They get recognized as Objective-C files, also .m, and improperly identified/highlighted. Github does highlight Matlab m files if they have the .matlab extension, but the problem with this is that Matlab seems to refuse to run files that that don't have the .m extension. I haven't been able to come up with a solution, as I'd like my matlab files to play nicely with both Github and Matlab. So here are couple of questions:

  1. Is there a way to have all .m files converted to .matlab extensions when pushed to Github? This would also need to convert .matlab files to .m extensions when fetching or cloning from Github?

  2. If 1. isn't possible, is there a way to get Matlab to run files that have a .matlab extension?

If yes to either 1 or 2, I'd love some tips or examples of how to do this.

like image 678
moorepants Avatar asked Oct 11 '22 22:10

moorepants


2 Answers

You can use git hooks to do point 1 in your question. If you look in .git/hooks/, you'll find some examples that you can use (what the different files do are explained here). Basically all you need to do is add a post-receive hook that will rename the files from .m to .matlab on github and a post-fetch or post-pull hook (might be fudging my terminologies a little here) that will rename them back to .m files.

Also, take a look at some of the related questions on git hooks on SO: 1, 2, 3, 4, and many more...

That said, I agree with Alex that it's generally not a good idea to change the extension between repositories, as you can end up breaking code for others who might use your scripts.

like image 114
abcd Avatar answered Oct 17 '22 00:10

abcd


Check to see if Github will respect your attributes file(s). If so then set up a pattern for *.m and set the approprtiate attributes to ge the right viewing style.

The attributes file is also a place for the matlab LF normalisation of eol=LF (even on Windows) git-crlf-conversion-for-m-matlab-files

like image 22
Philip Oakley Avatar answered Oct 17 '22 01:10

Philip Oakley