Delgan Delgan - 1 year ago 80
Git Question

How to correctly work on a GreaseMonkey userscript using git?

I am working on a userscript for Firefox, so I use GreaseMonkey. Moreover, to facilitate the development, I use git to update the different versions of my code.

Now, let me try to explain the issue.

When I add to GreaseMonkey the userscript from my local git directory, then new files are created in the gm_scripts folder of my Firefox profile.

GreaseMonkey use these files as source and not my git directory, so if I want to modify my code and test some stuff, I have to change the files inside the gm_scripts. This means that I can not commit the modification, I first have to copy the files from gm_scripts to my git directory. This is really unconvenient.

There is another solution. I can also modify the script from my git directory, and then re-install it to GreaseMonkey using a bookmark pointing to these local files. But once again, this is not handy at all.

What I thought third was to define the folder inside the gm_scripts as my git directory. Unfortunatly, my project contains many files that I ordered into folders, and I want to keep it clean. But adding an userscript to GreaseMonkey makes all the files to be extract from their folder.


Moreover, my git project does not contains only the userscript folder, there is some other stuff. So it is probably not a good idea to declare a gm_script's directory as a source for git, putting many files in gm_scripts whereas they had nothing to do with a userscript is not a good method. And it is not right to be forced to have to work in a folder lost in the depths of my Firefox profile.

I would like to know if there was a technique to work efficiently and easily on a project including both GreaseMonkey and git.

Answer Source

You could link the necessary files!

Windows (Elevated Command Prompt): mklink <<gmfile>> <<gitfile>>

Unix/Linux: ln -s <<gitfile>> <<gmfile>

Thank you to Enkidu from the Greasespot discussion group for his response!

Using Windows and a .bat file, this code is used to link all the files from you git folder to the Greasemonkey one (it may have errors if there are spaces in the paths or if two of your files have the same name).

echo off

set git_dir=C:\path\to\your\git\folder
set gm_dir=C:\path\to\your\greasemonkey\userscript\folder\

for /R %git_dir% %%G IN (*) do (
    echo Y | del %gm_dir%%%~nxG
    mklink %gm_dir%%%~nxG  %%G
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download