Skip to content

Instantly share code, notes, and snippets.

@dlo
Created February 9, 2011 17:47
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dlo/818881 to your computer and use it in GitHub Desktop.
Save dlo/818881 to your computer and use it in GitHub Desktop.
Using filesystem events and git to version my Notational Velocity notes
Interim Note-Changes
.DS_Store

Notational Velocity + Git + Python

After reading Steve Ivy's blog post yesterday about how he hooked his Notational Velocity notes with his Github wiki, I was inspired to do the same with Python.

Installation

Python Module Setup

Install the Python libraries specified in the requirements file with pip:

sudo pip install -r requirements.txt

Then grab the Growl SDK from Growl's homepage and install the Python module.

One thing you will need to do to get GitPython working as a service is to edit where the Git binary is located. Run which git to find where it is. Then, in cmd.py (for me, it's located at /Library/Python/2.6/site-packages/git/cmd.py), change

call = ["git", dashify(method)]

to

call = ["/where/your/binary/lives/git", dashify(method)]

Git Setup

Store your Notational Velocity notes as plain text files and move the directory to something like ~/Documents/Notes. Add the included .gitignore.

git init
git add .
git commit -m "first commit"

Next thing you should do is add a remote. Set up a bare repo in your Dropbox or whatever you want to use to sync up your repos between computers. E.g.

cd ~/Dropbox/Documents
mkdir Notes.git
cd Notes.git
git init --bare

Now go back to ~/Documents/Notes and set this repo as your origin.

cd ~/Documents/Notes
git remote add origin ~/Dropbox/Documents/Notes.git
git push origin master

Script Setup

Move nvwatcher.py to /usr/local/bin. Change the path variable on line 10 to point to your ~/Documents/Notes location (must be an absolute path). Download the Notational Velocity icon file to get a pretty image for each Growl message. Then make the file executable with

chmod +x nvwatcher.py

Move me.dlo.nvwatcher.plist to ~/Library/LaunchAgents/ and run

sudo launchctl load ~/Library/LaunchAgents/me.dlo.nvwatcher.plist

Now you're done! When you use Notational Velocity, you will see a Growl message for each note change you make.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>me.dlo.nvwatcher.plist</string>
<key>ProgramArguments</key>
<array>
<string>python</string>
<string>/usr/local/bin/nvwatcher.py</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/usr/local/var/log/nvwatcher.log</string>
<key>StandardOutPath</key>
<string>/usr/local/var/log/nvwatcher.log</string>
</dict>
</plist>
#!/usr/bin/env python
import Growl as growl
from fsevents import Observer, Stream
import git
notifier = growl.GrowlNotifier("Notational Velocity", [""])
notifier.register()
path = "/Users/dan/Documents/Notes"
repo = git.Repo(path)
observer = Observer()
observer.start()
# Download the Notational Velocity icon from the Github repo
image = growl.Image.imageFromPath("/Users/dan/Downloads/Notality.icns")
def callback(subpath, mask):
if repo.is_dirty():
repo.git.add(".")
response = repo.git.commit(m="automated commit")
repo.remote().push()
notifier.notify(noteType="", title="Notational Velocity",
description=response, icon=image)
stream = Stream(callback, path)
observer.schedule(stream)
-e git+git://github.com/gitpython-developers/GitPython.git
MacFSEvents
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment