Wednesday, September 3, 2008

Setting up a quick-and-dirty notes "repository"

I constantly find myself with quick "todo" tasks popping up and having to remember little details about a lot of different technologies.

To solve this, I used to keep a "Notes" directory which contains a "todo.txt" file and dozens of other text files with snippets of information (apache.txt contains little tidbits on Apache configuration, capistrano.txt contains information on setting up capistrano, aws.txt contains information about Amazon's Web Services I've found over the years, etc).

I would set up an alias so that the "todo" command would run something like "vim ~/Notes/todo.txt" and the "notes" command would run something like "vim ~/Notes" which would in turn show a directory of all of the notes.

This system let me quickly update my todo list by typing "todo" at a prompt, edit the file via vim, then :wq to save and go back to my work.

This worked well when I was on one machine predominantly, but now that I have to switch between multiple machines (Mac and PC) I find my notes out of date (or not accessible if I am on the other machine).

Therefore, I could either carry around local storage (such as a USB memory stick which I know will always leave plugged into the "wrong" computer) or put the notes on a network accessible server. I chose the second option.

While this might seem like a good job for a Ruby on Rails web service (and it probably is), I still wanted to use vim from a command line quickly and not have to open a browser window/authenticate/edit with an HTML editor/save as you would with a web service. I just wanted to touch files quickly without disturbing my workflow.

Here is how I set this up to work with my server. [Note: you need to have ssh access]

On the Mac

1. Make sure ssh works without needing a password (Instructions: http://rcsg-gsir.imsb-dsgi.nrc-cnrc.gc.ca/documents/internet/node31.html)

You should be able to do "ssh user@hostname.com" and be signed in at this point.

2. Create a Notes directory on the server (in your home directory). I name mine "Notes" so it is always visible, but you can use ".notes" or whatever you like as long as you use the same name below.
3. Create a script named "nvim" in /usr/local/bin

vim scp://user@hostname.com/Notes/$1

4. run "sudo chown root:wheel nvim"
5. run "sudo chmod 755 nvim"

You should be able to do "nvim todo.txt" and edit the ~/Notes/todo.txt file on the server without needing to type a password.

For extra convenience, I created two aliases "todo" and "notes" which run "nvim todo.txt" and "nvim" respectively. This lets you simply type "todo" or "notes" and you are off and editing you're server-based repository.

On the PC

1. Since you will be using ssh/scp, you will need a Posix or *nix subsystem. I use msysGit (http://code.google.com/p/msysgit/) but Cygwin or putty will also work with the method below.
2. Make sure ssh works without needing a password (Instructions: http://rcsg-gsir.imsb-dsgi.nrc-cnrc.gc.ca/documents/internet/node31.html)

You should be able to do "ssh user@hostname.com" and be signed in at this point.

3. If you haven't done this from the Mac yet, create a Notes directory on the server (in your home directory). I name mine "Notes" so it is always visible, but you can use ".notes" or whatever you like as long as you use the same name below.
4. Create a script named "nvim" in /bin. Neither the msysGit or Cygwin versions of vim support scp so I created a simple wrapper to download the file:

scp user@hostname.com:Notes/$1 /tmp/$1
vim /tmp/$1
scp /tmp/$1 user@hostname.com:Notes/$1
rm /tmp/$1

Note that the scp command has a colon after the server and before the directory (not a slash as in the vim command).

I created an alias "todo" which calls "nvim todo.txt". Unfortunately, with this download/edit/upload method you will need to know the name of the file. I created a "notes" script which lists all of the files in the Notes directory on the server:

ssh user@hostname.com 'ls Notes'

That's all there is to it.

If you need to fgrep the Notes directory, use the ssh command to run fgrep on the server.

1 comment:

Phil said...

I created a very basic online todo.txt editor at
http://www.garven.net/todo


You need you own place to host it but it's as simple as you can get - doesn't tie you down to one machine.