Aug 10, 2013

Create OmniFocus Project with AppleScript

At work one of my duty is to take care of purchase orders for my team mates. The workflow involve always the same three steps.

Being an Omnifocus user, I wrote a small AppleScript that takes as input a purchase description and as output creates a main task with three sub tasks in Omnifocus directly.

-- Entry point when run

on run
    display dialog "Enter purchase order description:" default answer "Purchase"
    createOmniFocusTask(the result's text returned)
end run

-- Create tasks in Omnifocus

on createOmniFocusTask(eventName)
    tell application "OmniFocus"
        tell default document
            -- Grab the context
            set purchaseContext to first context whose name is "Emarsys"

            -- Create the task inside a project
            set fld to first folder whose name is "Emarsys"
            tell fld
                set proj to first project whose name is "Single Actions"
                tell proj
                    -- Create parent task and its subtasks.
                    set parentTask to make new task with properties {name:eventName, sequential:true}
                    tell parentTask
                        make new task with properties {name:"Print Formular for " & eventName, context:purchaseContext}
                        make new task with properties {name:"Get the Sign for " & eventName, context:purchaseContext}
                        make new task with properties {name:"Order for " & eventName, context:purchaseContext}
                    end tell
                end tell
            end tell
        end tell
    end tell
end createOmniFocusTask

Copy and paste that into a new script in AppleScript Editor (or download a copy here) and try it out.

Of course, you have to adapt a little bit if you do not have an Emarsys context.

Jan 28, 2013

Protect Your Private Data Using Gitconfig Include Directive

I am using a dotfiles git repository in order to keep my machine preferences in sync.

This is working pretty well, until you realise that are some config entries that are clashing with each other.

One of those cases, is the common situation of having two github accounts -- one for work and one for private purposes. In this case we would like to share the common git configuration but not the committer's author name and email address held in the .gitconfig.

Recently, git added a new feature, the include directive for config files ( since 1.7.10 ) that can solve the problem. With the include feature you can split your gitconfig across multiple files, so you can have the common git configuration in one file, and private information in another.

Let's have a look at an example :

  • Add the include directive to your .gitconfig ( this is the file in your git dotfiles repository )
     [include]
           path = ~/.gitconfig_user
    
  • Add to ~/.gitconfig_user your private data
[user]
     name = Silvio Berlusconi
     email = silvio.berlusconi@bungabunga.it
 
  • Test if the config is working properly
$ git config user.name
Silvio Berlusconi
$ git config user.email
silvio.berlusconi@bungabunga.it

May 12, 2012

Extract a Directory From a Git Branch/Repository Preserving The History

At work we wanted to extract from a branch a subdirectory containing a specific feature that had to be used from everyone in the team.

Just for sake of example, let's define the terms of our problem. Our repository (MAIN) structure looks like:

MAIN/
        Library/
            libA/
            libB/
            libC/

Our goal is to extract the libA contained in the branch FTR-B in its own branch called FTR-A.

If you are not interested in preserving the history the task is quite easy. Git checkout is our friend in this case.

$ git checkout master
$ git checkout -b FTR-A
$ git checkout FTR-B Library/libA
$ git commit -a -m "Extract libA"
$ git push

More complicated is the case in which preserving the history is a matter of importance. For God's sake git has a powerful command git filter-branch. The following are my notes and observations, for pleasing my poor memory.

  • Clone the local repository into a temporary repository DIRTY.
$ git clone ~/MAIN/ ~/DIRTY/
$ cd DIRTY
$ git checkout FTR-B
  • Remove everything except the desired subdirectory ( libA ).
$ git filter-branch --prune-empty --tree-filter 'rm -rf Library/libB Library/libC'

Basically, Git filter-branch executes a command on each commit in a specific branch. Instead of the option tree-filter you could have used subdirectory-filter that removes everything except the desired directory moving it up to the root project. I will explain it better in another post.

  • Clean all the cruft
$ git gc --aggressive
  • Merge the new feature in its own branch FTR-A.
$ cd ~/MAIN
$ git remote add dirty ~/DIRTY
$ git fetch dirty
$ git branch dirty remotes/tools/FTR-B
$ git checkout master
$ git checkout -b FTR-A
$ git merge dirty
$ git remote rm dirty
  • Create a pull request

Apr 18, 2012

How to fetch upstream changes in git easily

It is quite common to update your git fork repository with the upstream changes.

Here it is the workflow I use to keep synchronize my branch with Octopress.

  • First of all, we should configure the remotes.
$ git remote add upstream git://github.com/imathis/octopress.git
  • Check the remotes
    $ git remote
    
  • Merge/Rebase the changes
    $ git fetch origin -v
$ git fetch upstream -v
$ git merge upstream/master
    

If you prefere you can create an alias in your .gitconfig.

[alias]
  pull_upstream = !"git fetch origin -v; git fetch upstream -v; git merge upstream/master"

Now git pull_upstream will fetch the changes of both remotes, and the merge in the upstream changes.

Feb 04, 2012

Back Online

It has been nearly four years since I last posted. Quite a lot. Anyhow, now I am back online thanks to Octopress and Github pages.

I'll have more to do:

  • write a catch up post
  • importing the old posts parked here after my previous Django blog abandoned me.
  • personalized the Octopress default template.