├── bin └── vw-update.pl ├── setup.pl └── README.md /bin/vw-update.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | ## 4 | # 5 | my $USER=`whoami`; 6 | my $WATCH_PATH=$ARGV[0]; 7 | 8 | my $GROWL = `PATH="\$PATH:/usr/local/bin";which growlnotify`; 9 | chomp $GROWL; 10 | 11 | my $GIT = _find_bin('git/bin/git'); 12 | unless (-f $GIT) { 13 | die ("No Git found!"); 14 | } 15 | 16 | _check_watch_dir($WATCH_PATH); 17 | 18 | my $status= `cd $WATCH_PATH; $GIT status`; 19 | 20 | if ($status =~ /modified|untracked\ files\ present|deleted/) { 21 | my $out = `cd $WATCH_PATH; $GIT add .; $GIT commit -a -m "Veloci-Wiki Update"; $GIT push;`; 22 | _log("Your Notes Wiki was updated:\n$out"); 23 | 24 | ### use growl if available 25 | if (-f $GROWL) { 26 | `$GROWL 'Veloci-Wiki Update' -m "Your Notes Wiki was updated:\n$out"`; 27 | } 28 | } else { 29 | _log("No update needed."); 30 | } 31 | 32 | ##### 33 | 34 | sub _log { 35 | my $msg = shift; 36 | print "vw-update: $msg\n"; 37 | } 38 | 39 | sub _check_watch_dir { 40 | my $wd = shift; 41 | if (! -d "$wd/.git") { 42 | _log("Watch directory ($wd) is not a Git repository!"); 43 | exit(1); 44 | } 45 | 1; 46 | } 47 | 48 | sub _find_bin { 49 | my $target = shift; 50 | my $paths = `locate $target`; 51 | my @paths = split(qr{\n},$paths); 52 | my $res=$paths[0]; 53 | return $res; 54 | } -------------------------------------------------------------------------------- /setup.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | my $WATCH_PATH = $ARGV[0]; 7 | 8 | unless($WATCH_PATH) { 9 | die "Usage: $0 " 10 | } 11 | 12 | print "Setting up veloci-wiki...\n"; 13 | 14 | my $USER = `whoami`; 15 | chop $USER; 16 | 17 | my $CWD = `pwd`; 18 | chop $CWD; 19 | 20 | _check_watch_dir($WATCH_PATH); 21 | 22 | _log("Watching: $WATCH_PATH"); 23 | 24 | my $PLIST_ID = "local.$USER.veloci-wiki-update"; 25 | 26 | my $plist = <<"PLIST"; 27 | 28 | 29 | 30 | 31 | Disabled 32 | 33 | Label 34 | $PLIST_ID 35 | ProgramArguments 36 | 37 | perl 38 | $CWD/bin/vw-update.pl 39 | $WATCH_PATH 40 | 41 | StartInterval 42 | 300 43 | 44 | 45 | PLIST 46 | 47 | if (! -d "/Users/$USER/Library/LaunchAgents") { 48 | _log("Creating LaunchAgents directory..."); 49 | `mkdir /Users/$USER/Library/LaunchAgents`; 50 | } 51 | 52 | _log("Creating launchd plist for watcher at:"); 53 | _log("/Users/$USER/Library/LaunchAgents/$PLIST_ID.plist"); 54 | 55 | open(my $plist_file, '>', 56 | "/Users/$USER/Library/LaunchAgents/$PLIST_ID.plist") or die $!; 57 | print $plist_file $plist; 58 | close($plist_file); 59 | 60 | _log("Restarting launchd..."); 61 | `launchctl unload ~/Library/LaunchAgents/`; 62 | `launchctl load ~/Library/LaunchAgents/`; 63 | 64 | ##### 65 | 66 | sub _log { 67 | my $msg = shift; 68 | print "$msg\n"; 69 | } 70 | 71 | sub _check_watch_dir { 72 | my $wd = shift; 73 | if (! -d "$wd/.git") { 74 | _log("Watch directory ($wd) is not a Git repository!"); 75 | exit(1); 76 | } 77 | 1; 78 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Veloci-Wiki 2 | 3 | Veloci-wiki is not a wiki, per se. Rather, it's an easy way to set up your [Notational Velocity](http://notational.net) install to store note data in a [Github](http://github.com) wiki. This makes NV a great note editor AND a great wiki editor! 4 | 5 | See the first blog post [here](http://monkinetic.com/2011/02/08/wiring-notational-velocity-to-a-github-wiki.html) for more info. 6 | 7 | # Usage 8 | 9 | ## Github Setup 10 | 11 | First up, get the code: 12 | 13 | % git clone git@github.com:sivy/veloci-wiki.git 14 | 15 | If you prefer, fork the project first, then create a local clone. 16 | 17 | If you don't already have a repository on Github that you want to use for your NV wiki, create a new respository (Github has [excellent help](http://help.github.com/) if you need it) and create the wiki for the repo by going to "Wiki" and clicking "Create Wiki" 18 | 19 | 20 | 21 | After you have your wiki, click the "Git Access" button on the wiki home page and copy the git URL, which will look something like: `git@github.com:/.wiki.git` 22 | 23 | 24 | 25 | Clone the wiki repo somewhere on your local drive and write down or copy the path: 26 | 27 | % git clone git@github.com:/.wiki.git 28 | % cd .wiki; pwd | pbcopy 29 | 30 | In the cloned veloci-wiki repo, run: 31 | 32 | % perl setup.pl 33 | 34 | You should see something like: 35 | 36 | % perl setup.pl /Users/you/tmp/veloci-wiki.wiki 37 | Setting up veloci-wiki... 38 | Watching: /Users/you/tmp/veloci-wiki.wiki 39 | Creating launchd plist for watcher at: 40 | /Users/you/Library/LaunchAgents/local.you.veloci-wiki-update.plist 41 | Restarting launchd... 42 | 43 | You can ignore any warnings like: 44 | 45 | % launchctl: Error unloading: 46 | 47 | ## Notational Velocity Setup 48 | 49 | You are using it, or downloaded it, right? 50 | 51 | Launch NV if it's not running. Open the Preferences and click on "Notes". Next to "Read notes from folder", pick "Other..." from the drop down and select the directory into which you cloned your wiki. 52 | 53 | 54 | 55 | Then, click on "Storage" and change your settings to use "Plain Text Files" (in [nvalt](http://brettterpstra.com/code/notational-velocity-alt/), a fork of Notational Velocity, I use the "Zettelkasten (Markup text Files)" setting, but it works either way): 56 | 57 | 58 | 59 | Finally, to make sure that NV creates markdown (`.md`) files by default, select (or create an entry for) ".md" in the list of file extensions and then click the checkmark icon below the list. This sets `.md` as the default extension for files (Github only recognizes `.md` files as wiki pages). 60 | 61 | # It's alive! 62 | 63 | Now, after making a change in Notational Velocity, you should see your page appear on your Github wiki under "Pages". If you have Growl installed, the update script will find it and report: 64 | 65 | --------------------------------------------------------------------------------