Posts Tagged ‘automation’


Sunday, February 12th, 2012

Update: Ooops, I guess we gone incremented the year again… and no one thought to tell me :(


It’s comforting to know that the people we elect to rule us at least know what they’re doing… Oh… wait…

git and branches

Last week, for the first time, I think I groked branches. The headline mentions git branches, and if they are different from other VCS’ branches, then last week I think I groked git branches :P

I’ve known about branching for quite a while, but never gotten past anything other than a rudimentary understanding.

I think I understood how mercurial does it (simply clone the repository, name the root directory of that clone to whatever you want to call that branch, and presto. (And yes, I am aware that mercurial has a branch command as well, so my understanding on that point is probably incorrect).

Either way, what finally gave me an “aha”-moment was this blogpost.

And while one the subject: Other uses of git. I am going to take a closer look at especially Prophet.



No but seriously, frakking do it. Automation ftw.


Tuesday, April 19th, 2011

fsniper is one of those really neat tools I’ve found while just taking a stroll through the repositories, but for which I’ve never quite found a good use.

What fsniper does is that it watches one or more directories, for the addition of files of various mime types or that holds a file name that matches a regular expression, and executes a command or a script, aimed at manipulating that file.

Let’s try a practical use for this (thank you bio-geeks for the idea):

I have a bin directory in my home folder (i.e. ${HOME}/bin), and obviously every script I put in that directory should be executable.

watch {
    $HOME/bin {
        *.sh {
            handler = chmod o+x %%

This short example shows what is needed:

  1. We need to know WHERE fsniper should look
  2. We need to know WHAT fsniper should react on
  3. Finally, we need to know HOW fsniper should react

Every now and then I also do a little bit of python coding, so I might want to make these executable as well.

watch {
    $HOME/bin {
        *.sh {
            handler = chmod o+x %%

        *.py {
            handler = chmod o+x %%

The syntax is rather easy to work with, there are just a couple of special stuff (i.e. %% and the accompanying %f and %d)

%% will expand to mean /the/full/path/to/this/file, with %f expanding to the file name and %d expanding to /the/full/path/to/this/

You get the picture.

And as for the matching rules above, yes, I could have used regular expressions akin to /.*\.(sh|py)/ but then I wouldn’t have been able to show you how to expand on the example.

And just like I added another file name matcher, I could just as easily add another directory to watch.

So right now you are probably wondering, where should this configuration file be put? The answer is: ~/.config/fsniper/config

Then there is the small matter of running fsniper, as follows:
$ fsniper --daemon

If you start it up, and check ~/.config/fsniper again, you will notice a log file aptly named “log”. This contains some really handy output for debugging your configuration when things doesn’t do what you expect them to.

Finally, in the ~/.config/fsniper directory you can also create a subdirectory named “scripts”, and fsniper will make sure to append that directory to the $PATH variable.

Very handy for creating handler-scripts for use only with fsniper.

In closing, I just want to say that fsniper can be a bit more complex than this, acting differently based upon what the exit code of a handler was (i.e. we can engineer our scripts to fail graciously, triggering fsniper to try the next handler defined for that directory).

So if I have piqued your interest I wholeheartedly recommend that you check out the following resources:

Thanks for reading, hope you found it useful :)